This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Macro Expansion with NANA

Hello All,

I am trying to use the GNU NANA in my project for Invariants and Quantifiers. I am facing some issues with macro expansion (the macros are already written by NANA people).

Whenever I use the MACRO (A, E, and C)in my code and compile it, I get an error as "error: #29: expected an expression". The way I am using it is as in following code snippet:

int main(void)
{
  int q[5] = {1,2,3,4,5};
  I(q[4] == 5);
  N(q[4] == 5);
  I(A(temp = 0, temp < 5, temp++, q[temp] <= 5));
  return 0;
}

I got above error for line "I(A(temp = 0, temp < 5, temp++, q[temp] <= 5));"

I have also seen the expanded macro in the preprocessed file and it look like this:

int main(void)
{
  int q[5] = {1,2,3,4,5};

  do { if((1)) { if(!(q[4] == 5)) { _I_default_handler("I(" "q[4] == 5" ")","test.c",8); } } } while(0);
  do { if((1)) { if(!((!(q[4] == 5)))) { _I_default_handler("N(" "q[4] == 5" ")","test.c",9); } } } while(0);

  do { if((1)) { if(!(({ int _A_result = 1; temp = 0; while(temp < 5) { if(!(q[temp] <= 5)) { _A_result = 0; break; } temp++; } _A_result; }))) { _I_default_handler("I(" "A(temp = 0, temp < 5, temp++, q[temp] <= 5)" ")","test.c",15); } } } while(0);

  return 0;
}

There is some problem while returning _A_result. I tried compliling this with CodeSourcery, and it works fine with that.

Does keil not work well with macros?

Thanks in advance

Parents
  • Not sure how much documentation you read.

    ftp.gnu.org/.../nana_2.html

    Some important nuggets to consider:
    "Nana makes use of two GNU extensions in its library so you really should be using 'gcc'. Some of the code can be used with any C compiler, though it may not be worth the bother. The dependencies on gcc are in 'Q.h' which uses the statement value extension and in 'L.h' which uses the variable number of arguments extension to 'cpp'."

    And under known problems:
    "The 'Q.h' macros depend on the statement value extension to GNU CC so if you wish to use them you must use GCC. This can be fixed for C++ in a possibly useful manner, I can't see any solution for C."

    So maybe you should reconsider your question "Does Keil not work well with macros?"

Reply
  • Not sure how much documentation you read.

    ftp.gnu.org/.../nana_2.html

    Some important nuggets to consider:
    "Nana makes use of two GNU extensions in its library so you really should be using 'gcc'. Some of the code can be used with any C compiler, though it may not be worth the bother. The dependencies on gcc are in 'Q.h' which uses the statement value extension and in 'L.h' which uses the variable number of arguments extension to 'cpp'."

    And under known problems:
    "The 'Q.h' macros depend on the statement value extension to GNU CC so if you wish to use them you must use GCC. This can be fixed for C++ in a possibly useful manner, I can't see any solution for C."

    So maybe you should reconsider your question "Does Keil not work well with macros?"

Children