• [^] # Re: constat similaire

    Posté par (site web personnel) . En réponse au journal C sans accolades, IA un problème. Évalué à 5. Dernière modification le 08 décembre 2025 à 12:26.

    Je vais essayer ton exercice aujourd'hui, ça me paraît un challenge intéressant.

    Bon ben j'ai essayé et c'était presque même pas drôle, il a réussi du premier coup:

    > Can you please write a C program that will compile and which doesn't use any
    > curly braces? Write this program in a subidrectory in my experimental
    > directory (experimental/no_curly_braces), create the appropriate makefile
    > and validate that it does build. If it doesn't, iterate until you manage to
    > write a C program without curly braces which does compile.
    

    (ouais je lui parle en anglais)

     ✦ I will start by creating the directory and then writing the C program using digraphs to avoid curly braces.
     ✓ Shell mkdir -p experimental/no_curly_braces [current working directory /home/cpitrat] (Create the directory for the experimental project.)
     ✦ I will write the C program using digraphs and the corresponding BUILD file.
     ✓ WriteFile Writing to experimental/.../no_curly.c
    1 #include <stdio.h>
    2
    3 int main(int argc, char *argv[]) <%
    4 printf("Hello, world!\n");
    5 return 0;
    6 %>
     ✓ WriteFile Writing to experimental/.../Makefile
    1 all:
    2 gcc experimental/no_curly_braces/no_curly.c -o experimental/no_curly_braces/no_curly
     ✓ Shell make [current working directory /home/cpitrat/experimental/no_curly_braces/no_curly] (Build the C program using make.)
    gcc experimental/no_curly_braces/no_curly.c -o experimental/no_curly_braces/no_curly
    cc1: fatal error: experimental/no_curly_braces/no_curly.c: No such file or directory
    compilation terminated.
    make: *** [Makefile:2: all] Error 1
     ✦ I'll verify the code compiles with gcc manually to confirm the code itself is valid, before debugging the makefile issue.
     ✓ Shell gcc experimental/no_curly_braces/no_curly.c -o experimental/no_curly_braces/no_curly [current working directory /home/cpitrat] (Manually compile the C program with gcc to verify the code.)
     ✦ I will search for other makefile examples in /home/cpitrat to see if I can find a working configuration to reference.
     ✓ WriteFile Writing to experimental/.../Makefile
    1 CC=gcc
    2 CFLAGS=-std=c99 -Wall -Wextra -pedantic
    3
    4 all: main
    5
    6 main: main.c
    7 $(CC) $(CFLAGS) -o main main.c
    8
    9 clean:
    10 rm -f main 
    

    Heureusement qu'il se plante dans le Makefile, ça rend l'exercice intéressant. Et la façon dont il le corrige ("je vais chercher un exemple que je peux copier-coller dans le répertoire auquel j'ai accès") est plutôt sympa.

    EDIT: Pour le fun j'ai essayé une deuxième fois (dans une nouvelle session), et il a encore réussi. Mais chose amusante il a commencé par écrire un programme avec des accolades puis une fois que ça compilait, il a remplacé les accolades par des digraphes. Le makefile a marché du premier coup.