Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » syntax error for preprocessor macro, even after defining symbol(Can't stop some preprocessor macros from showing up as syntax errors)
syntax error for preprocessor macro, even after defining symbol [message #631544] Thu, 07 October 2010 21:53 Go to next message
LaurenV is currently offline LaurenVFriend
Messages: 1
Registered: October 2010
Junior Member
I have a define for my ARM cross compile toolchain that is:

#define PACKED __packed


I then define a struct as follows:

typedef PACKED struct {
 char x;
 int y;
}MY_STRUCT;


This definition comes up highlighted as a syntax error(fixed if I remove the PACKED keyword). and It doesn't index the structure.

I have tried adding an empty symbol in "Paths and Symbols" for PACKED and __packed for all languages and re-indexed. This did not solve the problem.

Thanks for your time.



Re: syntax error for preprocessor macro, even after defining symbol [message #790204 is a reply to message #631544] Fri, 03 February 2012 23:51 Go to previous messageGo to next message
Vynce - is currently offline Vynce -Friend
Messages: 6
Registered: January 2012
Junior Member
I realize that this is an old thread, but I'm running into exactly the same issue on an embedded ARM project.

It's possible to work around the issue with some preprocessor magic, but it would be nice if there was some way to just tell Eclipse/CDT to ignore the __packed keyword somehow. We've got __packed keywords scattered all over the place and it would be quite an undertaking to replace all of them just to make Eclipse index the structures.

Any ideas?

// Define NO_PACKED_SUPPORT in Eclipse and leave
// it undefined for hardware builds.

#ifdef NO_PACKED_SUPPORT
    #define PACKED
    #define PACKED_STRUCT struct
#else
    #define PACKED __packed
    #define PACKED_STRUCT __packed_struct
#endif


typedef PACKED struct {
    char x;
    int y;
} MY_STRUCT;

typedef PACKED_STRUCT {
    char x;
    int y;
} MY_STRUCT2;

[Updated on: Sat, 04 February 2012 00:02]

Report message to a moderator

Re: syntax error for preprocessor macro, even after defining symbol [message #791824 is a reply to message #790204] Mon, 06 February 2012 09:54 Go to previous messageGo to next message
Harry Houdini is currently offline Harry HoudiniFriend
Messages: 142
Registered: February 2010
Senior Member
The C & C++ standards say it is so illegal to define identifiers starting with __.
Re: syntax error for preprocessor macro, even after defining symbol [message #791974 is a reply to message #790204] Mon, 06 February 2012 13:34 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Here is a workaround mentioned
http://www.eclipse.org/forums/index.php/mv/msg/204292/654556/#msg_654556

you should add the symbol NO_PACKED_SUPPORT to Project Properties->C/C++ Paths and Symbols


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: syntax error for preprocessor macro, even after defining symbol [message #792589 is a reply to message #791974] Tue, 07 February 2012 06:48 Go to previous messageGo to next message
Dirk Wibben is currently offline Dirk WibbenFriend
Messages: 50
Registered: February 2010
Member
Hi,

the solution in this thread

http://www.eclipse.org/forums/index.php/mv/msg/162043/512293/#msg_512293

worked great for me.

If added the following

// When the CDT parser from Eclipse indexes, the part with '@' is empty
#ifndef __CDT_PARSER__
   #define SFR_AT(location)   @##location
#else
   #define SFR_AT(location)
#endif


And the usage looks like this:

#define dDSA1     0xFFFB1

volatile TByte ioDSA1 SFR_AT(dDSA1);


HTH
Dirk


Best regards
Dirk
Re: syntax error for preprocessor macro, even after defining symbol [message #792705 is a reply to message #792589] Tue, 07 February 2012 10:03 Go to previous messageGo to next message
Axel Mueller is currently offline Axel MuellerFriend
Messages: 1973
Registered: July 2009
Senior Member
Dirk Wibben wrote on Tue, 07 February 2012 07:48
Hi,

the solution in this thread

http://www.eclipse.org/forums/index.php/mv/msg/162043/512293/#msg_512293

worked great for me.

If added the following

// When the CDT parser from Eclipse indexes, the part with '@' is empty
#ifndef __CDT_PARSER__
   #define SFR_AT(location)   @##location
#else
   #define SFR_AT(location)
#endif


And the usage looks like this:

#define dDSA1     0xFFFB1

volatile TByte ioDSA1 SFR_AT(dDSA1);


HTH
Dirk

Cool. I did not know about the __CDT_PARSER__ symbol. Can you add this to the CDT FAQ please? http://wiki.eclipse.org/CDT/User/FAQ


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: syntax error for preprocessor macro, even after defining symbol [message #1384470 is a reply to message #631544] Thu, 29 May 2014 04:08 Go to previous message
J Ferguson is currently offline J FergusonFriend
Messages: 1
Registered: May 2014
Junior Member
Found a better solution (doesn't require you to muck up your code):

1. Go into project properties
2. under "C/C++ General > Paths and Symbols"
3. Select the "Symbols" tab
4. Select "GNU C" for language
5. Click the "Add" button beside the symbol list
6. Enter "__packed" in the Name field, and nothing in the Value field
7. Apply settings, problem solved

Surprised
Previous Topic:Text highlight
Next Topic:Don't add space before block-comments
Goto Forum:
  


Current Time: Fri Apr 26 21:34:34 GMT 2024

Powered by FUDForum. Page generated in 0.03954 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top