mity / md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
MIT License
756 stars 138 forks source link

-Wmissing-braces warning with clang on MacOS #125

Closed guillaumechereau closed 3 years ago

guillaumechereau commented 3 years ago

Can be easily fixed by replacing {0} with {} as suggested by clang:

[ 12%] Building C object src/CMakeFiles/md4c.dir/md4c.c.o
/Users/guillaume/src/md4c/src/md4c.c:1580:35: warning: suggest braces around initialization of subobject [-Wmissing-  braces]
    MD_UNICODE_FOLD_INFO a_fi = { 0 };
                                  ^
                                  {}
/Users/guillaume/src/md4c/src/md4c.c:1581:35: warning: suggest braces around initialization of subobject [-Wmissing-braces]
    MD_UNICODE_FOLD_INFO b_fi = { 0 };
                                  ^
                                  {}
mity commented 3 years ago

Unfortunately, empty braces are not really a valid C variable initializer, not even in C99. Many compilers support it as an extension because it has been added into C++, but not all of them.

guillaumechereau commented 3 years ago

I see... Actually the suggested fix by clang is to use { {} }. Would that work?

mity commented 3 years ago

Oops, a race condition. No {} would work, even when nested. AFAIK, in a pedantic C, it can only express an empty code block, not a variable initializer.

But it should already be fixed in 70d0ef7.

guillaumechereau commented 3 years ago

Thanks! Perfect. I directly compile md4c source alongside my code, so it's nice that it compiles with -Wall by default.