C listing: unknown type name

I have this simple code:

#include <stdio.h> #include <time.h> int main(){ enum Days { asd=0,Lun,Mar,Mer,Gio,Ven,Sab,Dom }; Days TheDay; time_t ltime; struct tm *Tm; ltime=time(NULL); Tm=localtime(&ltime); int j = Tm->tm_wday; TheDay = Days(j); printf("[%d] %d/%d/%d, %d:%d:%d\n", TheDay, /* Mon - Sun */ Tm->tm_mday, Tm->tm_mon, Tm->tm_year+1900, Tm->tm_hour, Tm->tm_min, Tm->tm_sec); } 

I do not understand why I am getting this error:

try.c: 6: 5: error: unknown type name 'Days

+4
source share
1 answer

This is not C:

 enum Days { asd=0,Lun,Mar,Mer,Gio,Ven,Sab,Dom }; Days TheDay; 

The name of the new type is enum Days , not Days (this is the enum tag).

You should use:

 enum Days { asd=0,Lun,Mar,Mer,Gio,Ven,Sab,Dom }; enum Days TheDay; 

or use typedef:

 typedef enum Days Days; 

to be able to use Days as the type name.

+19
source

All Articles