1

I have written a few blocks of _Generic code, but there seems to be a few errors.The code is written in a file which is included in 3 other files and the three files are incluled in the main file. The errors:

D:\Data\Projects\4. Progetto di Tirana - #2\main.c:7:
D:\Data\Projects\4. Progetto di Tirana - #2\amministratoreFile.c: In function 'startAmm':
D:\Data\Projects\4. Progetto di Tirana - #2\strfnx.c:84:37: error: expected specifier-qualifier-list before ')' token
84 | )(lista)
D:\Data\Projects\4. Progetto di Tirana - #2\amministratoreFile.c:20:3: note: in expansion of macro 'scaricaDati'
20 | scaricaDati(&dati);"

In the other lines the code is similar just the number of the line changes. A few examples where I use the code:

void aggiungiProf(){
struct professore *lista, dati;
scaricaDati(&lista);

dati.ID = lunghezzaLista(lista);
dati.stato = 1;
printf("Inserisci il userName(nome+cognome) del professore da aggingere:\n");
scanf("%s", dati.userName);
strcpy(dati.passWord, (char*)generaPass(dati.ID, dati.userName));

inserisci_in_coda(&lista, &dati);
caricaCambiamenti(lista);
}

Here is the code:

#define confermaCredenziali(credenziali, uN, pW)  _Generic((credenziali), \
                                  struct amministratore* :  confermaCredenzialiAmm, \
                                  struct professore* : confermaCredenzialiProf, \
                                  struct studente* : confermaCredenzialiStud \
                                )(credenziali, uN, pW)
#define visualizza(lista) _Generic((lista), \
                                  struct amministratore* : visualizzaAmmin, \
                                  struct professore* : visualizzaProf, \
                                  struct studente* : visualizzaStud \
                                )(lista)
#define caricaCambiamenti(lista) _Generic((lista), \
                                  struct amministratore* : caricaCambiamenti_Ammin, \
                                  struct professore* : caricaCambiamenti_Prof, \
                                  struct studente* : caricaCambiamenti_Stud, \
                                )(lista) //Here too
#define scaricaDati(lista) _Generic((lista), \
                                  struct amministratore** : scaricaDatiAmmin, \
                                  struct professore** : scaricaDatiProf, \
                                  struct studente** : scaricaDatiStud, \
                                )(lista) //Line were the error occurs 
#define inserisci_in_coda(lista, dati) _Generic((lista), \
                                  struct amministratore** : inserisci_in_coda_Ammin, \
                                  struct professore** : inserisci_in_coda_Prof, \
                                  struct studente** : inserisci_in_coda_Stud, \
                                )(lista) // Here too
#define lunghezzaLista(lista) _Generic((lista) , \
                                  struct amministratore* : lunghezzaLista_Ammin, \
                                  struct professore* : lunghezzaLista_Prof, \
                                  struct studente* : lunghezzaLista_Stud, \
                                )(lista) // Here
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Please provide a minimal coding example that demonstrates the error. Additionally, add the actual compiler errors that are generated. – JonBelanger Jul 19 '20 at 16:58
  • What happens when you remove the trailing comma from the association list? – Shawn Jul 19 '20 at 17:11
  • @Shawn I removed the all the \ from the first block and "#2\strfnx.c:66:62: error: expected identifier or '(' before ':' token 66 | struct amministratore* : confermaCredenzialiAmm," –  Jul 19 '20 at 17:26
  • The last **comma**, not the backslashes... – Shawn Jul 19 '20 at 17:37
  • @Shawn I get the following errors: "from D:\Data\Projects\4. Progetto di Tirana - #2\main.c:7: D:\Data\Projects\4. Progetto di Tirana - #2\amministratoreFile.c: In function 'aggiungiProf': D:\Data\Projects\4. Progetto di Tirana - #2\strfnx.c:85:40: error: too few arguments to function 'inserisci_in_coda_Prof' 85 | #define inserisci_in_coda(lista, dati) _Generic((lista), \" "in expansion of macro 'inserisci_in_coda' 76 | inserisci_in_coda(&lista, &dati);" "declared here 268 | void inserisci_in_coda_Stud(struct studente *lista, struct studente data){" –  Jul 19 '20 at 17:45
  • This code is related to [Overloading struct in C](https://stackoverflow.com/q/62939233/15168) — a previous question from Entiol Liko. – Jonathan Leffler Jul 19 '20 at 18:06
  • Please create an MCVE ([Minimal, Complete, Verifiable Example](https://stackoverflow.com/help/mcve)) (or MRE or whatever name SO now uses) or an SSCCE ([Short, Self-Contained, Correct Example](http://sscce.org/)). You should show a small piece of code that, when compiled, produces the errors you show in the question. You might decide to avoid one of the three types, for example. – Jonathan Leffler Jul 19 '20 at 18:08

0 Answers0