visual studio - Are synonymous `typedef`s in C interchangable? -


the declaration qboolean snddma_initdirect (void); appears in 'winquake/snd_win.c' on line 69. however, function's definition (appearing on line 183 of same file written as:

sndinitstat snddma_initdirect (void) {     /* actual implementation unimportant in discussion. */ } 

both qboolean, , sndinitstat typedefs of enumerations: sndinitstat on line 33 of 'winquake/snd_win.c',

typedef enum {sis_success, sis_failure, sis_notavail} sndinitstat; 

and qboolean in 'winquake/common.h' (line 30)

typedef enum {false, true} qboolean; 

these different enumerations.

i have been compiling source both visual studio 2015's built in compiler -- cl.exe -- , clang v3.7.1 via llvm plugin visual studio. clang states difference in declaration/definition error. visual studio compiles okay. who correct?

now, quote c: reference manual (fourth edition):

  • section 5.5 enumerated types (page 127)

    the enumeration constants specified when type defined , have type int.

  • section 5.10 typedef names (page 149)

    declarations typedef storage specifier not introduce new types; names considered synonymous types specified in other ways.

these 2 paragraphs read me if clang's error is, while helpful, incorrect according standard. know microsoft don't have greatest reputation correctly compiling c.

if enum types hidden behind typedef names qboolean , sndinitstat compatible, code ok. if not compatible, code erroneous. (see 6.2.7 compatible type , composite type).

if both function declarations present in same translation unit return type compatibility requirement becomes more strict point types have identical.

in case, 2 tagless enum types used define these typedef names. enum declarations sufficiently different make them incompatible. means code in question indeed contain error , clang right complain. visual studio misses error.

note though clang (as gcc) take extremity - report error when there's none. example, these declarations

enum { a1, a2, a3 } foo(); enum { b1, b2, b3 } foo(); 

result in same error in clang , gcc, though code valid. in example tagless enum types compatible, sufficient justify change in return type of foo between declarations.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -