Skip to main content



      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 17:53 Go to next message
Eclipse UserFriend
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 18:51 Go to previous messageGo to next message
Eclipse UserFriend
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: Fri, 03 February 2012 19:02] by Moderator

Re: syntax error for preprocessor macro, even after defining symbol [message #791824 is a reply to message #790204] Mon, 06 February 2012 04:54 Go to previous messageGo to next message
Eclipse UserFriend
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 08:34 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: syntax error for preprocessor macro, even after defining symbol [message #792589 is a reply to message #791974] Tue, 07 February 2012 01:48 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: syntax error for preprocessor macro, even after defining symbol [message #792705 is a reply to message #792589] Tue, 07 February 2012 05:03 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: syntax error for preprocessor macro, even after defining symbol [message #1384470 is a reply to message #631544] Thu, 29 May 2014 00:08 Go to previous message
Eclipse UserFriend
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: Thu Jul 10 04:43:31 EDT 2025

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

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

Back to the top