• Re: "C" code from bots (was Re: Oh d-ai-ry d-ai-ry me)

    From Tristan Wibberley@tristan.wibberley+netnews2@alumni.manchester.ac.uk to comp.lang.c on Tue Oct 21 14:03:48 2025
    From Newsgroup: comp.lang.c

    On 31/05/2025 12:53, Richard Heathfield wrote:
    On 31/05/2025 12:02, Janis Papanagnou wrote:

    Probably not, as my C90/C99 test more or less illustrated. It 'knew' of
    a syntax rule, but failed to apply it correctly.

    I just tried again, this time asking for a C90 program to produce a
    frequency count of colours in a 24-bit bitmap.

    It took three laps to make it C90-legal.

    To be fair, the number of times I cycle { compile, read syntax errors,
    edit my code } is usually more than 3. When I use Eclipse, I compile it
    and receive errors every line or so.


    --
    Tristan Wibberley

    The message body is Copyright (C) 2025 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Bonita Montero@Bonita.Montero@gmail.com to comp.lang.c on Tue Oct 21 15:51:34 2025
    From Newsgroup: comp.lang.c

    Am 30.05.2025 um 22:01 schrieb Richard Heathfield:
    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 <stdio.h>

    int main() {
        printf("Hello, world!\n");

        int x = 5;  // Declaration after executable code (invalid in C99)

        printf("x = %d\n", x);
        return 0;
    }

    Is this relevant to know today ?

    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.


    --- Synchronet 3.21a-Linux NewsLink 1.2