Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Bakul Shah
Using 0xfff...f instead of 0 for a null ptr might've been less "disgusting"! 

> On Nov 25, 2015, at 6:04 PM, Prof Brucee  wrote:
> 
> 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"  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  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");

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Ryan Gonzalez
I remember reading Jack Crenshaw's Let's Build a Compiler. In part 16, he 
mentioned that compiling an empty C source file on the VAX took 60 seconds and 
generated a 50K object file.

Link (just search for the text "vax"): 
http://compilers.iecc.com/crenshaw/tutor16.txt

(BTW, what exactly do you mean by "mmap of 0"?)

On November 25, 2015 8:57:11 PM CST, Prof Brucee  wrote:
>I am still fascinated by the VAX architecture manual which designates
>as
>"unpredictable" many things with consequences  including machine crash.
>Pissed that I can't get my vaxen to crash or burst into flames.
>On 26/11/2015 1:46 PM, "Brantley Coile"  wrote:
>
>> Bruce's law: undefined != stupid
>>
>> Sent from my iPad
>>
>> On Nov 25, 2015, at 9:04 PM, Prof Brucee 
>wrote:
>>
>> 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"  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 
>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);
>>>

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Prof Brucee
I am still fascinated by the VAX architecture manual which designates as
"unpredictable" many things with consequences  including machine crash.
Pissed that I can't get my vaxen to crash or burst into flames.
On 26/11/2015 1:46 PM, "Brantley Coile"  wrote:

> Bruce's law: undefined != stupid
>
> Sent from my iPad
>
> On Nov 25, 2015, at 9:04 PM, Prof Brucee  wrote:
>
> 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"  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  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, "#def

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
Bruce's law: undefined != stupid

Sent from my iPad

> On Nov 25, 2015, at 9:04 PM, Prof Brucee  wrote:
> 
> 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"  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  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, "#defin

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Prof Brucee
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"  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  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

Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Steffen Nurpmeso
plann...@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?

all that new C stuff and sequencing is shit.  imho :)

--steffen



Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
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  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, "externint 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++ 

Re: [9fans] Compiling ken-cc on Linux

2015-11-25 Thread Vasudev Kamath
Ryan Gonzalez  writes:

> See
> https://bitbucket.org/plan9-from-bell-labs/9-cc/issues/1/problems-building-under-x64-linux
> for some tips on fixing various errors you may encounter, including
> this one. (I opened that issue like 8 months ago...)

Thanks Ryan, I will follow this.



Re: [9fans] Compiling ken-cc on Linux

2015-11-25 Thread Ryan Gonzalez
See
https://bitbucket.org/plan9-from-bell-labs/9-cc/issues/1/problems-building-under-x64-linux
for some tips on fixing various errors you may encounter, including this
one. (I opened that issue like 8 months ago...)

On Wed, Nov 25, 2015 at 11:10 AM, Vasudev Kamath 
wrote:

>
> Hi,
>
> I'm trying to compile ken-cc from ¹. Its giving me following error
>
> cc -c -m32 -g -O
> -I/home/vasudev/Documents/C_programming/compilers/9-cc/Linux/386/include
> -I/home/vasudev/Documents/C_programming/compilers/9-cc/include -DLINUX_386
> -I../cmd/ 9obj.c
> In file included from
> /home/vasudev/Documents/C_programming/compilers/9-cc/Linux/386/include/lib9.h:9:0,
>  from 9obj.c:5:
> /usr/include/features.h:148:3: warning: #warning "_BSD_SOURCE and
> _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
>  # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use
> _DEFAULT_SOURCE"
>^
> 9obj.c:8:22: fatal error: 9c/9.out.h: No such file or directory
> compilation terminated.
> mk: cc -c -m32 ...  : exit status=exit(1)
> mk: for j in ...  : exit status=exit(1)
>
> I can't find 9c under src/cmd folder. Any hints on how to get it
> compiled?.
>
> Cheers,
>
> ¹ https://bitbucket.org/plan9-from-bell-labs/9-cc/overview
>
>


-- 
Ryan
[ERROR]: Your autotools build scripts are 200 lines longer than your
program. Something’s wrong.
http://kirbyfan64.github.io/


Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Ryan Gonzalez
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 == PRE

[9fans] Compiling ken-cc on Linux

2015-11-25 Thread Vasudev Kamath

Hi,

I'm trying to compile ken-cc from ¹. Its giving me following error

cc -c -m32 -g -O 
-I/home/vasudev/Documents/C_programming/compilers/9-cc/Linux/386/include 
-I/home/vasudev/Documents/C_programming/compilers/9-cc/include -DLINUX_386 
-I../cmd/ 9obj.c
In file included from 
/home/vasudev/Documents/C_programming/compilers/9-cc/Linux/386/include/lib9.h:9:0,
 from 9obj.c:5:
/usr/include/features.h:148:3: warning: #warning "_BSD_SOURCE and _SVID_SOURCE 
are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
 # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
   ^
9obj.c:8:22: fatal error: 9c/9.out.h: No such file or directory
compilation terminated.
mk: cc -c -m32 ...  : exit status=exit(1)
mk: for j in ...  : exit status=exit(1)

I can't find 9c under src/cmd folder. Any hints on how to get it
compiled?.

Cheers,

¹ https://bitbucket.org/plan9-from-bell-labs/9-cc/overview



Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread plannine
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?



Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
Dang it! I basically suck at proof reading! unintended consequences!

> On Nov 25, 2015, at 9:25 AM, Brantley Coile  wrote:
> 
> Insert various complaints about unwise complexities and their unindented 
> consequences here. 




Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
Insert various complaints about unwise complexities and their unindented 
consequences here. 

Just my personal taste, but I didn’t like shared libraries when the Unix world 
in the 1980’s were copying Window’s DLLs, and could never see the reason for 
linking the file system and paging system. Most thought it was neat that one 
could leverage the paging code to just mmap a file into their address space and 
just read it. At the time Dennis observed that storage was still larger than 
the address space of machines. This didn’t dissuade people to do that anyway, 
forever making the file system block size linked to the paging system on 
Unix-like systems.

Interesting that it is still causing problems.

Of course Plan 9 has neither shared libraries nor mmap. That’s a good thing.


> On Nov 25, 2015, at 8:48 AM, erik quanstrom  wrote:
> 
> so to answer bwc's question, no.  not always. 
> 
> On Nov 25, 2015 4:59 AM, Charles Forsyth  wrote:
> The link to the lwn.net article explains that using mmap the naughty 
> application mapped a page to virtual 0, which was then available in kernel 
> mode in that process, and all they'd need to do is put their own "socket" 
> structure at 0 + offsetof(struct tun_struct, sk).
> 
> On 25 November 2015 at 10:43, Brantley Coile  wrote:
> Just curious, will Linux not panic when the kernel deterrences a nil pointer?
> 
> Sent from my iPad
> 
> On Nov 25, 2015, at 5:27 AM, Alexandru Gheorghe  
> wrote:
> 
> On 11/23/2015 01:20 PM, Vasudev Kamath wrote:
> Ramakrishnan Muthukrishnan 
>  writes:
> 
> 
> Had been reading the SOSP paper:
> 
> 
> 
> 
> and this blog post that proposes a simpler C:
> 
> 
> I started reading the paper and its interesting. I didn't knew till date
> how optimizations really worked and why they were considered harmful.
> 
> 
> They can be quite harmful, the dereference example of tun->sk is a popular 
> example that dates from 2009 regarding the Linux Kernel being exploited by 
> Spender (Brad Spengler): https://lwn.net/Articles/342330/
> "a NULL pointer was dereferenced before being checked, the check was 
> optimized out by the compiler, and the code used the NULL pointer in a way 
> which allowed the attacker to take over the system"
> 
> Funny because Spengler did try many times to introduce better security in the 
> Linux Kernel (see his set of patches in collaboration with the PaX Team: 
> GRSEC) but was refused many times by the community and Linus in particular 
> due to performance penalties (among other "opinions"). Which again opens the 
> question where exactly is the undefined behavior problem? Resides on the 
> programmer or on the compiler (and its programmers)? And how do you deal with 
> the performance side? Because clearly, if you introduce more security then 
> you will start having penalties on it; I guess the question is how much are 
> you willing to let go in preference of more security and stable systems?
> 
> It's a very interesting paper, I only read 7 pages but will soon finish it 
> and go ahead with the references (probably it links the example I wrote in 
> the beginning of this e-mail).
> 
> Thanks for sharing.
> 
> -- 
> ; Alexandru Gheorghe
> ;
> ;   aGlobal
> ; 
> 
> 




Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread erik quanstrom
so to answer bwc's question, no.  not always.  
On Nov 25, 2015 4:59 AM, Charles Forsyth  wrote:The link to the lwn.net article explains that using mmap the naughty application mapped a page to virtual 0, which was then available in kernel mode in that process, and all they'd need to do is put their own "socket" structure at 0 + offsetof(struct tun_struct, sk).On 25 November 2015 at 10:43, Brantley Coile  wrote:Just curious, will Linux not panic when the kernel deterrences a nil pointer?Sent from my iPadOn Nov 25, 2015, at 5:27 AM, Alexandru Gheorghe  wrote:
  

  
  
On 11/23/2015 01:20 PM, Vasudev Kamath wrote:

  Ramakrishnan Muthukrishnan  writes:


  
Had been reading the SOSP paper:


and this blog post that proposes a simpler C:


  
  I started reading the paper and its interesting. I didn't knew till date
how optimizations really worked and why they were considered harmful.


They can be quite harmful, the dereference example of tun->sk
is a popular example that dates from 2009 regarding the Linux Kernel
being exploited by Spender (Brad Spengler):
https://lwn.net/Articles/342330/
"a NULL pointer was
  dereferenced before being checked, the check was optimized out by
  the
  compiler, and the code used the NULL pointer in a way which
  allowed the
  attacker to take over the system"

Funny because Spengler did try many times to introduce better
security in the Linux Kernel (see his set of patches in
collaboration with the PaX Team: GRSEC) but was refused many times
by the community and Linus in particular due to performance
penalties (among other "opinions"). Which again opens the question
where exactly is the undefined behavior problem? Resides on the
programmer or on the compiler (and its programmers)? And how do you
deal with the performance side? Because clearly, if you introduce
more security then you will start having penalties on it; I guess
the question is how much are you willing to let go in preference of
more security and stable systems?

It's a very interesting paper, I only read 7 pages but will soon
finish it and go ahead with the references (probably it links the
example I wrote in the beginning of this e-mail).

Thanks for sharing.

-- 
; Alexandru Gheorghe
;
;   aGlobal
; 
  





Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Charles Forsyth
The link to the lwn.net article explains that using mmap the naughty
application mapped a page to virtual 0, which was then available in kernel
mode in that process, and all they'd need to do is put their own "socket"
structure at 0 + offsetof(struct tun_struct, sk).

On 25 November 2015 at 10:43, Brantley Coile  wrote:

> Just curious, will Linux not panic when the kernel deterrences a nil
> pointer?
>
> Sent from my iPad
>
> On Nov 25, 2015, at 5:27 AM, Alexandru Gheorghe 
> wrote:
>
> On 11/23/2015 01:20 PM, Vasudev Kamath wrote:
>
> Ramakrishnan Muthukrishnan   writes:
>
>
> Had been reading the SOSP 
> paper: 
> 
>
> and this blog post that proposes a simpler 
> C: 
> 
>
> I started reading the paper and its interesting. I didn't knew till date
> how optimizations really worked and why they were considered harmful.
>
>
> They can be quite harmful, the dereference example of *tun->sk* is a
> popular example that dates from 2009 regarding the Linux Kernel being
> exploited by Spender (Brad Spengler): https://lwn.net/Articles/342330/
>
> "a NULL pointer was dereferenced before being checked, the check was
> optimized out by the compiler, and the code used the NULL pointer in a way
> which allowed the attacker to take over the system"
>
>
> Funny because Spengler did try many times to introduce better security in
> the Linux Kernel (see his set of patches in collaboration with the PaX
> Team: GRSEC) but was refused many times by the community and Linus in
> particular due to performance penalties (among other "opinions"). Which
> again opens the question where exactly is the undefined behavior problem?
> Resides on the programmer or on the compiler (and its programmers)? And how
> do you deal with the performance side? Because clearly, if you introduce
> more security then you will start having penalties on it; I guess the
> question is how much are you willing to let go in preference of more
> security and stable systems?
>
> It's a very interesting paper, I only read 7 pages but will soon finish it
> and go ahead with the references (probably it links the example I wrote in
> the beginning of this e-mail).
>
> Thanks for sharing.
>
> --
> ; Alexandru Gheorghe
> ;
> ;   aGlobal
> ; 
>
>


Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
My apologies for my iPad's spelling correction and my lack of proof reading. 
Proof reading is impotent. :)

I meant "dereference". It's an easy matter to have page zero invalid in both 
user space and kernel space. 

Sent from my iPad

> On Nov 25, 2015, at 5:43 AM, Brantley Coile  wrote:
> 
> Just curious, will Linux not panic when the kernel deterrences a nil pointer?
> 
> Sent from my iPad
> 
>> On Nov 25, 2015, at 5:27 AM, Alexandru Gheorghe  
>> wrote:
>> 
>>> On 11/23/2015 01:20 PM, Vasudev Kamath wrote:
>>> Ramakrishnan Muthukrishnan  writes:
>>> 
 Had been reading the SOSP paper:
 
 
 and this blog post that proposes a simpler C:
 
>>> I started reading the paper and its interesting. I didn't knew till date
>>> how optimizations really worked and why they were considered harmful.
>> 
>> They can be quite harmful, the dereference example of tun->sk is a popular 
>> example that dates from 2009 regarding the Linux Kernel being exploited by 
>> Spender (Brad Spengler): https://lwn.net/Articles/342330/
>> "a NULL pointer was dereferenced before being checked, the check was 
>> optimized out by the compiler, and the code used the NULL pointer in a way 
>> which allowed the attacker to take over the system"
>> 
>> Funny because Spengler did try many times to introduce better security in 
>> the Linux Kernel (see his set of patches in collaboration with the PaX Team: 
>> GRSEC) but was refused many times by the community and Linus in particular 
>> due to performance penalties (among other "opinions"). Which again opens the 
>> question where exactly is the undefined behavior problem? Resides on the 
>> programmer or on the compiler (and its programmers)? And how do you deal 
>> with the performance side? Because clearly, if you introduce more security 
>> then you will start having penalties on it; I guess the question is how much 
>> are you willing to let go in preference of more security and stable systems?
>> 
>> It's a very interesting paper, I only read 7 pages but will soon finish it 
>> and go ahead with the references (probably it links the example I wrote in 
>> the beginning of this e-mail).
>> 
>> Thanks for sharing.
>> 
>> -- 
>> ; Alexandru Gheorghe
>> ;
>> ;   aGlobal
>> ; 


Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Brantley Coile
Just curious, will Linux not panic when the kernel deterrences a nil pointer?

Sent from my iPad

> On Nov 25, 2015, at 5:27 AM, Alexandru Gheorghe  
> wrote:
> 
>> On 11/23/2015 01:20 PM, Vasudev Kamath wrote:
>> Ramakrishnan Muthukrishnan  writes:
>> 
>>> Had been reading the SOSP paper:
>>> 
>>> 
>>> and this blog post that proposes a simpler C:
>>> 
>> I started reading the paper and its interesting. I didn't knew till date
>> how optimizations really worked and why they were considered harmful.
> 
> They can be quite harmful, the dereference example of tun->sk is a popular 
> example that dates from 2009 regarding the Linux Kernel being exploited by 
> Spender (Brad Spengler): https://lwn.net/Articles/342330/
> "a NULL pointer was dereferenced before being checked, the check was 
> optimized out by the compiler, and the code used the NULL pointer in a way 
> which allowed the attacker to take over the system"
> 
> Funny because Spengler did try many times to introduce better security in the 
> Linux Kernel (see his set of patches in collaboration with the PaX Team: 
> GRSEC) but was refused many times by the community and Linus in particular 
> due to performance penalties (among other "opinions"). Which again opens the 
> question where exactly is the undefined behavior problem? Resides on the 
> programmer or on the compiler (and its programmers)? And how do you deal with 
> the performance side? Because clearly, if you introduce more security then 
> you will start having penalties on it; I guess the question is how much are 
> you willing to let go in preference of more security and stable systems?
> 
> It's a very interesting paper, I only read 7 pages but will soon finish it 
> and go ahead with the references (probably it links the example I wrote in 
> the beginning of this e-mail).
> 
> Thanks for sharing.
> 
> -- 
> ; Alexandru Gheorghe
> ;
> ;   aGlobal
> ; 


Re: [9fans] Undefined Behaviour in C

2015-11-25 Thread Alexandru Gheorghe
On 11/23/2015 01:20 PM, Vasudev Kamath wrote:
> Ramakrishnan Muthukrishnan  writes:
>
>> Had been reading the SOSP paper:
>> 
>>
>> and this blog post that proposes a simpler C:
>> 
> I started reading the paper and its interesting. I didn't knew till date
> how optimizations really worked and why they were considered harmful.

They can be quite harmful, the dereference example of *tun->sk* is a
popular example that dates from 2009 regarding the Linux Kernel being
exploited by Spender (Brad Spengler): https://lwn.net/Articles/342330/

"a NULL pointer was dereferenced before being checked, the check was
optimized out by the compiler, and the code used the NULL pointer in
a way which allowed the attacker to take over the system"


Funny because Spengler did try many times to introduce better security
in the Linux Kernel (see his set of patches in collaboration with the
PaX Team: GRSEC) but was refused many times by the community and Linus
in particular due to performance penalties (among other "opinions").
Which again opens the question where exactly is the undefined behavior
problem? Resides on the programmer or on the compiler (and its
programmers)? And how do you deal with the performance side? Because
clearly, if you introduce more security then you will start having
penalties on it; I guess the question is how much are you willing to let
go in preference of more security and stable systems?

It's a very interesting paper, I only read 7 pages but will soon finish
it and go ahead with the references (probably it links the example I
wrote in the beginning of this e-mail).

Thanks for sharing.

-- 
; Alexandru Gheorghe
;
;   aGlobal
; 



[9fans] 9atom, S-ATA hard disk not detected

2015-11-25 Thread Rudolf Sykora
Hello,

when trying to install 9atom I get to to the point
where I should presumably say that the installation should
go to the hard disc, but the only option I see is the usb
flash device from which I have run the installation itself.
I do not see any sd... under /dev.

It's a Samsung HD103Si S-ATA disc plugged into
P5GL-MX Asus mother board
http://dlcdnet.asus.com/pub/ASUS/mb/socket775/P5GL-MX/e_p5gl-mx.pdf
Bios detects it as the 3rd IDE master.

Can anybody tell me if there is any chance to have it run?

Thanks
Ruda