Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Abstract Syntax Tree for C programs Date: Sun, 26 May 2019 12:42:43 -0700 Organization: None to speak of Lines: 74 Message-ID: References: <1727e4f9-2056-4357-8572-599c46db6a88@googlegroups.com> <17344bb7-9c96-47eb-b006-c6c2e2b8bc59@googlegroups.com> <97b08cce-ec5d-4052-9338-0026b5d449bf@googlegroups.com> <87sgt339na.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="bd49e134f673f0f04f4092253526d6c8"; logging-data="16321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/UMj9RlKHjFcGbRX5E1Wka" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:IU/I5fKk6+RMZCtPU3M7giUALcI= sha1:R3dmoLWRjI/895dgttEPIFa1L3o= Xref: csiph.com comp.lang.c:144024 Bart writes: > On 24/05/2019 21:00, Ben Bacarisse wrote: >> Bart writes: >>> Type* makenewtype(int basetype){ >>> Type* t; >>> t = malloc(sizeof(Type)); >>> memset(t,0,sizeof(Type)); >>> t->typecode = basetype; >>> >>> return t; >>> }; >> >> The ; is not allowed here. Maybe you are using a permissive compiler. > > I didn't reply before as I thought this was about a typedef and you were > implying some special rules similar to those of compound statements. > > But trying to compile this: > > void F(void){}; > void G(void){}; > > I had quite a bit of trouble getting any compiler to notice the > semicolons. At best I could get clang or gcc to produce a warning. Take a look at the grammar. A lone semicolon inside a block is a "null statement". (It's a bit odd that a null statement is considered to be a kind of expression statement, but that's what the standard says.) Outside a block, at file scope, statements are not permitted, and there's no such thing as a null declaration. The extra semicolon is a syntax error. Many C compilers permit (and ignore) null declarations at file scope as an extension. I'm not surprised that you had trouble getting compilers to complain about the semicolons. In spite of being told many times, you pretend not to remember that with gcc and clang, you need to use something like "-std=c11 -pedantic" to enforce all the language rules, or "-std=c11 -pedantic-errors" to treat violations as fatal errors. You also pretend not to remember, in spite of being told many times, that the standard merely requires a "diagnostic" for a violation of a constraint or syntax rule, and that a non-fatal warning satisfies that requirement. > So, they are all fairly permissive. Without the semicolons, it means > this is allowed: > > void F(void) {} void G(void) {} > > which doesn't look right. I agree that putting two function definitions on a single line doesn't look right. But you seem to be pretending not to remember that, except for preprocessing directives, tokens can be separated by any kind of white space, including a space or a newline, so the above is exactly equivalent to this: void F(void) { } void G(void) { } (or whatever brace arrangement you prefer). I hope you're not under the impression that C prevents you from writing ugly and badly formatted code. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */