9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Prof Brucee <prof.brucee@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] Undefined Behaviour in C
Date: Thu, 26 Nov 2015 13:04:16 +1100	[thread overview]
Message-ID: <CAJDwFdhWy3y64Z_eRNzni2rhKjkwxXWWSX+06mPRgTeUwcvM-w@mail.gmail.com> (raw)
In-Reply-To: <AF4E572B-C7C4-41F2-B296-466A8F8038A6@me.com>

[-- Attachment #1: Type: text/plain, Size: 8869 bytes --]

gcc is indeed a very sad tome. The mmap of 0 is disgusting. I like kenc. It
just works. My behaviour this afternoon will be undefined but not as stupid
as that of some programmers.
On 26/11/2015 5:43 AM, "Brantley Coile" <brantleycoile@me.com> wrote:

> Align it to column 7 and it looks like all the code I saw when I started.
>
> iPhone email
>
> On Nov 25, 2015, at 12:13 PM, Ryan Gonzalez <rymg19@gmail.com> wrote:
>
> Neither! It's what happens when you run sed 's/^\s*//' on your whole code
> base, yielding results like (from cmd/yacc.c):
>
>
> void
> setup(int argc, char *argv[])
> {
> long c, t;
> int i, j, fd, lev, ty, ytab, *p;
> int vflag, dflag, stem;
> char actnm[8], *stemc, *s, dirbuf[128];
> Biobuf *fout;
>
> ytab = 0;
> vflag = 0;
> dflag = 0;
> stem = 0;
> stemc = "y";
> foutput = 0;
> fdefine = 0;
> fdebug = 0;
> ARGBEGIN{
> case 'v':
> case 'V':
> vflag++;
> break;
> case 'D':
> yydebug = ARGF();
> break;
> case 'a':
> yyarg = 1;
> break;
> case 'd':
> dflag++;
> break;
> case 'l':
> yyline = 0;
> break;
> case 'o':
> ytab++;
> ytabc = ARGF();
> break;
> case 's':
> stem++;
> stemc = ARGF();
> break;
> case 'S':
> parser = PARSERS;
> break;
> default:
> error("illegal option: %c", ARGC());
> }ARGEND
> openup(stemc, dflag, vflag, ytab, ytabc);
> fout = dflag?fdefine:ftable;
> if(yyarg){
> Bprint(ftable, "#define\tYYARG\t1\n\n");
> }
> if((fd = mkstemp(ttempname)) >= 0){
> tempname = ttempname;
> ftemp = Bfdopen(fd, OWRITE);
> }
> if((fd = mkstemp(tactname)) >= 0){
> actname = tactname;
> faction = Bfdopen(fd, OWRITE);
> }
> if(ftemp == 0 || faction == 0)
> error("cannot open temp file");
> if(argc < 1)
> error("no input file");
> infile = argv[0];
> if(infile[0] != '/' && getwd(dirbuf, sizeof dirbuf)!=nil){
> i = strlen(infile)+1+strlen(dirbuf)+1+10;
> s = malloc(i);
> if(s != nil){
> snprint(s, i, "%s/%s", dirbuf, infile);
> cleanname(s);
> infile = s;
> }
> }
> finput = Bopen(infile, OREAD);
> if(finput == 0)
> error("cannot open '%s'", argv[0]);
> cnamp = cnames;
>
> defin(0, "$end");
> extval = PRIVATE; /* tokens start in unicode 'private use' */
> defin(0, "error");
> defin(1, "$accept");
> defin(0, "$unk");
> mem = mem0;
> i = 0;
>
> for(t = gettok(); t != MARK && t != ENDFILE;)
> switch(t) {
> case ';':
> t = gettok();
> break;
>
> case START:
> if(gettok() != IDENTIFIER)
> error("bad %%start construction");
> start = chfind(1, tokname);
> t = gettok();
> continue;
>
> case TYPEDEF:
> if(gettok() != TYPENAME)
> error("bad syntax in %%type");
> ty = numbval;
> for(;;) {
> t = gettok();
> switch(t) {
> case IDENTIFIER:
> if((t=chfind(1, tokname)) < NTBASE) {
> j = TYPE(toklev[t]);
> if(j != 0 && j != ty)
> error("type redeclaration of token %s",
> tokset[t].name);
> else
> SETTYPE(toklev[t], ty);
> } else {
> j = nontrst[t-NTBASE].value;
> if(j != 0 && j != ty)
> error("type redeclaration of nonterminal %s",
> nontrst[t-NTBASE].name );
> else
> nontrst[t-NTBASE].value = ty;
> }
> case ',':
> continue;
> case ';':
> t = gettok();
> default:
> break;
> }
> break;
> }
> continue;
>
> case UNION:
> /* copy the union declaration to the output */
> cpyunion();
> t = gettok();
> continue;
>
> case LEFT:
> case BINARY:
> case RIGHT:
> i++;
>
> case TERM:
> /* nonzero means new prec. and assoc. */
> lev = t-TERM;
> ty = 0;
>
> /* get identifiers so defined */
> t = gettok();
>
> /* there is a type defined */
> if(t == TYPENAME) {
> ty = numbval;
> t = gettok();
> }
> for(;;) {
> switch(t) {
> case ',':
> t = gettok();
> continue;
>
> case ';':
> break;
>
> case IDENTIFIER:
> j = chfind(0, tokname);
> if(j >= NTBASE)
> error("%s defined earlier as nonterminal", tokname);
> if(lev) {
> if(ASSOC(toklev[j]))
> error("redeclaration of precedence of %s", tokname);
> SETASC(toklev[j], lev);
> SETPLEV(toklev[j], i);
> }
> if(ty) {
> if(TYPE(toklev[j]))
> error("redeclaration of type of %s", tokname);
> SETTYPE(toklev[j],ty);
> }
> t = gettok();
> if(t == NUMBER) {
> tokset[j].value = numbval;
> if(j < ndefout && j > 3)
> error("please define type number of %s earlier",
> tokset[j].name);
> t = gettok();
> }
> continue;
> }
> break;
> }
> continue;
>
> case LCURLY:
> defout(0);
> cpycode();
> t = gettok();
> continue;
>
> default:
> error("syntax error");
> }
> if(t == ENDFILE)
> error("unexpected EOF before %%");
>
> /* t is MARK */
> if(!yyarg)
> Bprint(ftable, "extern int yyerrflag;\n");
> Bprint(ftable, "#ifndef YYMAXDEPTH\n");
> Bprint(ftable, "#define YYMAXDEPTH 150\n");
> Bprint(ftable, "#endif\n" );
> if(!ntypes) {
> Bprint(ftable, "#ifndef YYSTYPE\n");
> Bprint(ftable, "#define YYSTYPE int\n");
> Bprint(ftable, "#endif\n");
> }
> if(!yyarg){
> Bprint(ftable, "YYSTYPE yylval;\n");
> Bprint(ftable, "YYSTYPE yyval;\n");
> }else{
> if(dflag)
> Bprint(ftable, "#include \"%s.%s\"\n\n", stemc, FILED);
> Bprint(fout, "struct Yyarg {\n");
> Bprint(fout, "\tint\tyynerrs;\n");
> Bprint(fout, "\tint\tyyerrflag;\n");
> Bprint(fout, "\tvoid*\targ;\n");
> Bprint(fout, "\tYYSTYPE\tyyval;\n");
> Bprint(fout, "\tYYSTYPE\tyylval;\n");
> Bprint(fout, "};\n\n");
> }
> prdptr[0] = mem;
>
> /* added production */
> *mem++ = NTBASE;
>
> /* if start is 0, we will overwrite with the lhs of the first rule */
> *mem++ = start;
> *mem++ = 1;
> *mem++ = 0;
> prdptr[1] = mem;
> while((t=gettok()) == LCURLY)
> cpycode();
> if(t != IDENTCOLON)
> error("bad syntax on first rule");
>
> if(!start)
> prdptr[0][1] = chfind(1, tokname);
>
> /* read rules */
> while(t != MARK && t != ENDFILE) {
> /* process a rule */
> rlines[nprod] = lineno;
> if(t == '|')
> *mem++ = *prdptr[nprod-1];
> else
> if(t == IDENTCOLON) {
> *mem = chfind(1, tokname);
> if(*mem < NTBASE)
> error("token illegal on LHS of grammar rule");
> mem++;
> } else
> error("illegal rule: missing semicolon or | ?");
> /* read rule body */
> t = gettok();
>
> more_rule:
> while(t == IDENTIFIER) {
> *mem = chfind(1, tokname);
> if(*mem < NTBASE)
> levprd[nprod] = toklev[*mem];
> mem++;
> t = gettok();
> }
> if(t == PREC) {
> if(gettok() != IDENTIFIER)
> error("illegal %%prec syntax");
> j = chfind(2, tokname);
> if(j >= NTBASE)
> error("nonterminal %s illegal after %%prec",
> nontrst[j-NTBASE].name);
> levprd[nprod] = toklev[j];
> t = gettok();
> }
> if(t == '=') {
> levprd[nprod] |= ACTFLAG;
> Bprint(faction, "\ncase %d:", nprod);
> cpyact(mem-prdptr[nprod]-1);
> Bprint(faction, " break;");
> if((t=gettok()) == IDENTIFIER) {
>
> /* action within rule... */
> sprint(actnm, "$$%d", nprod);
>
> /* make it a nonterminal */
> j = chfind(1, actnm);
>
> /*
> * the current rule will become rule number nprod+1
> * move the contents down, and make room for the null
> */
> for(p = mem; p >= prdptr[nprod]; --p)
> p[2] = *p;
> mem += 2;
>
> /* enter null production for action */
> p = prdptr[nprod];
> *p++ = j;
> *p++ = -nprod;
>
> /* update the production information */
> levprd[nprod+1] = levprd[nprod] & ~ACTFLAG;
> levprd[nprod] = ACTFLAG;
> if(++nprod >= NPROD)
> error("more than %d rules", NPROD);
> prdptr[nprod] = p;
>
> /* make the action appear in the original rule */
> *mem++ = j;
>
> /* get some more of the rule */
> goto more_rule;
> }
> }
>
> while(t == ';')
> t = gettok();
> *mem++ = -nprod;
>
> /* check that default action is reasonable */
> if(ntypes && !(levprd[nprod]&ACTFLAG) &&
> nontrst[*prdptr[nprod]-NTBASE].value) {
>
> /* no explicit action, LHS has value */
> int tempty;
>
> tempty = prdptr[nprod][1];
> if(tempty < 0)
> error("must return a value, since LHS has a type");
> else
> if(tempty >= NTBASE)
> tempty = nontrst[tempty-NTBASE].value;
> else
> tempty = TYPE(toklev[tempty]);
> if(tempty != nontrst[*prdptr[nprod]-NTBASE].value)
> error("default action causes potential type clash");
> }
> nprod++;
> if(nprod >= NPROD)
> error("more than %d rules", NPROD);
> prdptr[nprod] = mem;
> levprd[nprod] = 0;
> }
>
> /* end of all rules */
> defout(1);
>
> finact();
> if(t == MARK) {
> Bprint(ftable, "\n");
> if(yyline)
> Bprint(ftable, "#line\t%d\t\"%s\"\n", lineno, infile);
> while((c=Bgetrune(finput)) != Beof)
> Bputrune(ftable, c);
> }
> Bterm(finput);
> }
>
>
> On Wed, Nov 25, 2015 at 10:03 AM, <plannine@sigint.cs.purdue.edu> wrote:
>
>> On Wed, Nov 25, 2015 at 09:25:55AM -0500, Brantley Coile wrote:
>> > unindented consequences
>>
>> Is that a class of Python bugs or an awesome name for a Nerdcore band?
>>
>>
>
>
> --
> Ryan
> [ERROR]: Your autotools build scripts are 200 lines longer than your
> program. Something’s wrong.
> http://kirbyfan64.github.io/
>
>
>

[-- Attachment #2: Type: text/html, Size: 13996 bytes --]

  reply	other threads:[~2015-11-26  2:04 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-23 10:20 Ramakrishnan Muthukrishnan
2015-11-23 11:20 ` Vasudev Kamath
2015-11-25 10:27   ` Alexandru Gheorghe
2015-11-25 10:43     ` Brantley Coile
2015-11-25 10:53       ` Brantley Coile
2015-11-25 12:59       ` Charles Forsyth
2015-11-25 13:48         ` erik quanstrom
2015-11-25 14:25           ` Brantley Coile
2015-11-25 14:31             ` Brantley Coile
2015-11-25 16:03             ` plannine
2015-11-25 17:13               ` Ryan Gonzalez
2015-11-25 18:41                 ` Brantley Coile
2015-11-26  2:04                   ` Prof Brucee [this message]
2015-11-26  2:43                     ` Brantley Coile
2015-11-26  2:57                       ` Prof Brucee
2015-11-26  3:48                         ` Ryan Gonzalez
2015-11-26  7:27                     ` Bakul Shah
2015-11-26 11:22                       ` Brantley Coile
2015-11-26 11:37                         ` tlaronde
2015-11-26 11:55                           ` Charles Forsyth
2015-11-26 11:38                         ` Bruce Ellis
2015-11-26 16:31                         ` erik quanstrom
2015-11-26 16:42                           ` Brantley Coile
2015-11-26 16:50                             ` Charles Forsyth
2015-11-26 17:12                               ` erik quanstrom
2015-11-26 16:46                           ` Alexandru Gheorghe
2015-11-26 17:48                         ` Bakul Shah
2015-11-26 18:04                           ` Brantley Coile
2015-11-26 23:14                           ` Steve Simon
2015-11-26 23:24                             ` Charles Forsyth
2015-11-26 23:55                             ` Brantley Coile
2015-11-25 19:19               ` Steffen Nurpmeso
2015-11-23 11:32 ` Charles Forsyth
2015-11-23 11:37   ` Charles Forsyth
2015-11-23 11:50 ` Brantley Coile
2015-11-23 12:05   ` Charles Forsyth
2015-11-23 12:17     ` Brantley Coile
2015-11-23 12:40       ` Charles Forsyth
2015-11-23 12:09   ` Charles Forsyth
2015-11-23 14:30 ` Charles Forsyth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJDwFdhWy3y64Z_eRNzni2rhKjkwxXWWSX+06mPRgTeUwcvM-w@mail.gmail.com \
    --to=prof.brucee@gmail.com \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).