meekrosoft / fff

A testing micro framework for creating function test doubles
Other
766 stars 167 forks source link

Macro usage examples yield empty declarations #32

Open gsauthof opened 7 years ago

gsauthof commented 7 years ago

Inspired by the documentation in the readme file I created this small test program:

#include <fff.h>
DEFINE_FFF_GLOBALS; // WARNING

FAKE_VALUE_FUNC(double, pow, double, double); // WARNING

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
  pow_fake.return_val = 23;
  printf("pow: %f\n", pow(2, atoi(argv[1])));
  return 0;
}

This works as expected with gcc on Fedora 25. But on Solaris 10/SPARC with the Solaris Studio 12.3 C compiler I get the following warnings:

"test.c", line 2: warning: syntax error:  empty declaration
"test.c", line 4: warning: syntax error:  empty declaration

Looking at the C pre-processor output reveals the cause:

DEFINE_FFF_GLOBALS;
FAKE_VALUE_FUNC(double, pow, double, double);

The expansion of both macros yields an extra semicolon!

Thus, removing the semicolons in the test program eliminates the warnings:

DEFINE_FFF_GLOBALS
FAKE_VALUE_FUNC(double, pow, double, double)

Thus, perhaps you want to change the macro definitions such that no superfluous semicolons are expanded anymore. This would increase the portability of this header-only library.

See also:

Empty declarators are prohibited; a declaration must be a static_assert declaration or (since C11) have at least one declarator or declare at least one struct/union/enum tag, or introduce at least one enumeration constant.

(http://en.cppreference.com/w/c/language/declarations)