Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Ar Rakin Newsgroups: comp.lang.c Subject: Re: Oh d-ai-ry d-ai-ry me Date: Tue, 3 Jun 2025 22:06:50 +0600 Organization: OSN Lines: 77 Message-ID: <101n6iq$45oj$1@dont-email.me> References: <101d2re$l1ta$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 03 Jun 2025 18:06:51 +0200 (CEST) Injection-Info: dont-email.me; posting-host="fb5a63833d1ca0431395a8385205fb57"; logging-data="136979"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UU2b9z7EQNG9nmU/HmuWIbZdPtUhfHiQ=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:tB8ePZyGvZfvJhdCbRZG4z0aKjc= In-Reply-To: <101d2re$l1ta$1@dont-email.me> Content-Language: en-US On 5/31/25 2:01 AM, Richard Heathfield wrote: > This evening I accidentally bumped into a chatbot, and I wondered > whether it was any good at C programming. > > I was impressed when it solved Goldbach's Conjecture (admittedly for > small n) and 5-disc Hanoi, but then I thought back to a recent thread > here (which I have no intent of resurrecting), so I asked it if it could > have saved me a job if I'd only asked it a few hours ago. > > Judge for yourselves! > > I asked: "Write a program that is valid C90 but invalid C99." > > ChatGPT said: > > Certainly! To illustrate this, I'll write a C program that is valid in > C90 but invalid in C99. The key difference between C90 and C99 revolves > around variable declaration and initialization. > Key Issue: > >     In C90, variables can only be declared at the beginning of a block > (before any executable code). > >     In C99, variables can be declared anywhere within a block, even > between statements. > > C Program Example: > > This program is valid in C90 but invalid in C99 because the variable x > is declared after executable code. > > #include > > int main() { >     printf("Hello, world!\n"); > >     int x = 5;  // Declaration after executable code (invalid in C99) > >     printf("x = %d\n", x); >     return 0; > } > > Why it’s Valid in C90: > >     In C90, all variable declarations must appear at the beginning of a > block (before any code). This program would be valid in C90 because x is > declared after the printf statement, but only the declaration of x > itself breaks the rule in C99. > > Why it’s Invalid in C99: > >     In C99, variables can be declared anywhere within a block, even > after executable statements (not just at the beginning of a block). This > is why the above code would cause an error in C99, as the variable x is > declared after a statement (printf). > > Compilation Example: > > If you compile this program with a C99 compiler (e.g., GCC), you'll get > an error similar to this: > > error: variable 'x' declared after statement > > To summarize: > >     C90 allows this style (declaration after code). > >     C99 does not allow it, so the program becomes invalid. > This is the reason why I tell people who write code that AI/LLMs can't ever replace them like this. AI tools can only be a tool that you use. To write code, you'd still need to know something by yourself at the end of the day. -- Rakin