Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro usage examples yield empty declarations #32

Open
gsauthof opened this issue Apr 27, 2017 · 0 comments
Open

Macro usage examples yield empty declarations #32

gsauthof opened this issue Apr 27, 2017 · 0 comments
Labels

Comments

@gsauthof
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants