3

Hi I have been trying to port LWIP to a new arm device. When compiling the code i get the error message:

"lwip/lwip-1.4.0/src/include/lwip/memp_std.h:35:23: error: expected ')' before numeric constant"

When I go to this file this and below this several similar macros is what I find on that line:

LWIP_MEMPOOL(RAW_PCB, MEMP_NUM_RAW_PCB,         sizeof(struct raw_pcb),        "RAW_PCB")

If I remove the need for this macro with a define to deactivate the RAW functionality the error moves to the next LWIP_MEMPOL() macro.

The define it seems to want to put a ')' in front of is defined as this:

#define MEMP_NUM_RAW_PCB          1

The RAW_PCB is not defined but is "combined with MEMP_" to create an element in an enum.

I have tried to complie the whole ting with the -E option to get human redable object files and see if i can find any open '(' around the areas where MEMP_RAW_PCB apears and the substitution of MEMP_NUM_RAW_PCB to 1 but I have not found any by manual inspection yet.

Are there any suggestions on what can be going on here or what more I can do or look for to find the cause of the error?

I should maybe add that so far I don't call on any of the LWIP code from main() or any of the functions used in main().

ElvishPriestley
  • 45
  • 1
  • 1
  • 8
  • 2
    I recommend to have a look at the pre-processor out generated from the line in question. – alk Aug 22 '13 at 14:35
  • That was fast, thanks :). Yes that's what I do when I use the -E option to get the .o files. I guess i should take an even closer look :). Any idea what I should look for? – ElvishPriestley Aug 22 '13 at 14:51
  • The pre-processor somehow generates invalid code from the macro on `memp_std.h:35`. Do inspect this code. – alk Aug 22 '13 at 14:59
  • Can you show the definition of `LWIP_MEMPOOL`? – lurker Aug 22 '13 at 15:07
  • 2
    `memp_std.h` is #include'd repeatedly, to create various structures which need per-memory-pool entries. It would certainly be useful to know where you are in the #include hierarchy when this error appears, so that you can tell which invocation of `#include "lwip/memp_std.h"` is causing the problem. – rici Aug 22 '13 at 15:22
  • 1
    The `LWIP_MEMPOOL` invocation you show is missing the semicolon. Is that is the real code, or a typo in this question? – jxh Aug 22 '13 at 16:14
  • LWIP defines, undefines and redefines LWIP_MEMPOL multiple times. Il try to copy paste these defines in the text. – ElvishPriestley Aug 22 '13 at 17:15
  • This is how it is writen in the memp_std.h file. I thougt it was a bit strang that there were no ';' in the file but as this is library code I thought that maby who ever wrote it knew what they wer doing or would have made corections if it was wrong, and then I stoped thinking about it. I checked now in the 4.1.1 version of LWIP and it had the same memp_std.h file. But definitly strange. I will have to check this to morow I'm curently not on the PC with the project. – ElvishPriestley Aug 22 '13 at 17:22
  • Compiled it today with ';' but that just made gcc complain about lacking identifier before ;. I think seing as the macro is used the way it is, it cant have an ending ;. – ElvishPriestley Aug 23 '13 at 07:28
  • I finally got it to compile. I don't know exactly what the problem was. But whoever had done the port I was basing my port on had made one huge (relatively) .h file with all the .h files found in the include folder of lwip. When I removed these includes I could finally get errors that I could easily solve. If however I re include the other files again it stops at the same line. Thanks in anny case for all your help! \(^_^)y – ElvishPriestley Aug 23 '13 at 12:33

3 Answers3

2

I solved it with:

#ifndef MEMP_STD_H_ 
#define MEMP_STD_H_

... // memp_std.h codes ...

#endif //#ifndef MEMP_STD_H_
Xavi López
  • 27,550
  • 11
  • 97
  • 161
wii
  • 36
  • 2
  • Haha header guards did not think of that at all. I guess this should be reported as a bug to the LWIP maintainers. I'm currently not working with it but I believe you when you say this solves the problem. – ElvishPriestley Mar 12 '14 at 14:00
0

The error suggests you have unbalanced parentheses. The code you have provided thus far does not indicate where this problem is, but since ) is expected, it probably means the error is actually in the lines of code preceding the one you have shown.

Examine the code preceding the line you have shown (perhaps after using gcc -E) to check to see if all the parentheses are balanced.

jxh
  • 69,070
  • 8
  • 110
  • 193
  • The code that is above it in the memp_std.h file consists of defines and ifdefs (with endifs) there are no open '(' in that file. I have been trying to find the error in the precompiled .o files after compiling with the -E option but so far I have not found it. I will give it another shot to morrow. – ElvishPriestley Aug 22 '13 at 18:06
0

If you're defining it with the dash-D option, it will generate the 1 by default, e.g.:

gcc -D 'MAX(A,B) ((A) < (B)? (B) : (A))' ...

Generates:

#define MAX(A,B) ((A) < (B)? (B) : (A)) 1

And you get the error: expected ‘)’ before numeric constant message at the line where the substitution occurs because of that trailing 1, e.g.:

int maxval = MAX(i,j);
// generates: int maxval = ((i) < (j)? (j) : (i)) 1;

Conversely, if you use the assignment operator to explicitly define the value, it will generate it the way you expected. E.g.:

int maxval = MAX(i,j);
// generates: int maxval = ((i) < (j)? (j) : (i));
Luv2code
  • 1,079
  • 8
  • 14