CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Maximum number of #defines?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

Maximum number of #defines?
PostPosted: Thu Apr 17, 2008 12:00 pm     Reply with quote

I'm using PCH version 4.071 with a PIC18F8722 target on a gigantic (129684 bytes ROM used) application. The program is comprised of 19 header files and 17 C files. The problem I am about to describe originally happened on 4.068, and I upgraded to 4.071 but it has the same issue.

We start with a working, compiling program, that is error free. Then I add one new definition:
Code:
#define LOG_CONDENSATE      0x04      // Emergency shut down due to condensate overflow

I get an error
Quote:
Error 53 "C:\Devel\PIC-C\Atlanta\Atlanta-RTC.c" Line 31(1,8): Expecting function name

The error refers to a completely different system, and does not look like an error to me (and remember, it compiled before we added the new definition). Here is Line 31 from the referenced file:
Code:
fprintf(TERM,"Low battery! (%lu VE2)",m);

If I simply remark the new #define out of the code, the project once again compiles successfully.

Just to cover the bases, I have tried moving the #define to a different location of the header file, I have tried changing its name altogether, and I have changed its value. In all cases the project will not compile, reporting the same error, until I remove this define. At one point I remarked out about 5K of program just to make sure we have plenty of room, and got the same results (works with define remarked, error when defined).

Since it does not seem to have to do with the name, the value, or the location, I now have to wonder if there is a maximum number of defines in PCH?

Thanks in advance!
-Kyle
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 1:13 pm     Reply with quote

grasping at straws here:

Try commenting out line 31

Try commenting out line 31, and/or 1 or 2 lines before/after

Try commenting out 1 or 2 lines before/after the #define

Try this #define with some other define(s) commented out.

Debugging a compiler is such fun Smile

Best of luck!

Ken
horkesley



Joined: 20 Feb 2007
Posts: 48
Location: Essex UK

View user's profile Send private message Send e-mail Visit poster's website

CCS compiler limitations
PostPosted: Thu Apr 17, 2008 2:08 pm     Reply with quote

Hi,

This is very interesting.

I am about to start a large project and plan to use the 18F8722.

I have used the CCS compiler/ ICD-U40 on a few projects using the 18F4520 and have not been completly satisfied with the ease of use.

I have been considering different compilers and when I read about these sorts of problems it make me think I should move away from CCS.

I am not interested in debugging compilers.

I use Microsoft Studio and write in VB.NET and C++ and I dont have these problems.

I shall follow your thread with interest.

Regards and good luck
_________________
Horkesley Electronics Limited
Ttelmah
Guest







PostPosted: Thu Apr 17, 2008 2:25 pm     Reply with quote

Also, look at the lines immediately in front of the 'new' definition, and search the entire project for 'LOG_CONDENSATE'.
There is a common problem, which occurs particularly in CCS (but I have seen examples, even in compilers like VC++), where one change, can 'trigger' another fault, that is normally already present, but for some reason was being masked by things that followed, and then is revealed/shows up, somewhere miles away. A 'classic' example, would be (for instance), a line that lacks it's ';' some distance in front of the new definition, but happens to get correctly terminated by a semi-colon some lines latter. Changing a line in between the actual error, and the 'lucky' termination, results in the original error changing it's effect....

Best Wishes
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 3:09 pm     Reply with quote

Ttelmah and the rest,

Thanks for the input. I searched the entire project and the only reference to LOG_CONDENSATE is in this header file. The project is almost 18K lines long. So far, I have been unable to find any other problems at all. At my wits end, I will post here the entire header file which contains the new definition. I cannot remark out other defines as they are required in the program.
Code:
///////////// Includes /////////////
#include "Dev-AT24C64.c"
#include "Lib-GCSerialLog.c"
#include "Lib-Conversions.c"

///////////// Global Definitions /////////////
#define LOGSIZE       DEVAT24C64A_SIZE
#define LOGADDRESS       DEVAT24C64A_ADDR0

#define LOG_MALLOCFAIL      0x00
#define LOG_FREEZE         0x01
#define LOG_LUP            0x02
#define LOG_HOP            0x03
//#define LOG_CONDENSATE      0x04

#define LOG_PORESET          0x10
#define LOG_SENSORMISSING   0x11

#define LOG_TIME_CHANGE      0x20
#define LOG_FIRMWARE_UPD   0x21
#define LOG_ET_SET         0x22
#define LOG_NC_SET         0x23
#define LOG_SETTINGS_SET   0x24

#define LOG_RESET_BUTTON   0x80
#define LOG_TESTMODE         0x81

#define LOGMOD_NULL         0x00
enum logmodStartStop8 {LOGMOD_START,LOGMOD_STOP};
enum logmodET8 {LOGMOD_ET_C1,LOGMOD_ET_C2,LOGMOD_ET_S3,LOGMOD_ET_BM,LOGMOD_ET_LP,LOGMOD_ET_STRIPS};   
enum logmodCycles8 {LOGMOD_NC_C1,LOGMOD_NC_C2};
enum logmodSettings8 {LOGMOD_SETTINGS_PDA,LOGMOD_SETTINGS_FACTORY,LOGMOD_SETTINGS_BIOS};

///////////// Prototypes /////////////
void AtlLOG_Init(void);
int1 AtlLOG_EntryGet (int16 mLogAddr, int8 *iMemBlock);
void AtlLOG_EntrySet(int8 iEntryType, int8 iEntryModifier=LOGMOD_NULL, void *pEntryData=NULL);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 3:41 pm     Reply with quote

What is the total number of #define statements in your program ?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Apr 17, 2008 4:50 pm     Reply with quote

Quote:
I cannot remark out other defines as they are required in the program.
I've never seen a program using all defines present. Even if you do need all the defines in your part of the program than there are the hundreds of defines in all the standard include files.

As a simple test to see if the large number of defines has reached some kind of compiler limit you could try commenting out one of the defines in a compiler supplied header file, for example in 18F8722.h file.

Quote:
Error 53 "C:\Devel\PIC-C\Atlanta\Atlanta-RTC.c" Line 31(1,8): Expecting function name
Can you post line 25 to 35 of Atlanta-RTC.c?
Ttelmah
Guest







PostPosted: Fri Apr 18, 2008 2:32 am     Reply with quote

One thought does 'rear it's head'.
It is possible, that CCS, just happen to use the keyword 'LOG_CONDENSATE' themselves, somewhere internally. Obviously not as a 'define' (since this would then just result in a duplicate define warning), but possibly as an internal function name, inside the maths library for example.
Try just changing the name, to something like 'CONDENSATE_LOG', and see if the problem disappears.

Best Wishes
kamputty
Guest







PostPosted: Fri Apr 18, 2008 12:10 pm     Reply with quote

Kyle,

Create a "Hello World" program (same mcu) with lets say 1000(?) defines and see if that works. Keep adding until you blow it up (if it does). The compiler could be getting confused with "code"+"defines"...who knows!

Okay, I just tested this...

Compiler: 3.234

Simple program, just the end result from the PICWizard for a pic18f4520, no other code other then the initial wizard stuff

I created 10,000 (ten thousand) defines

Code:

#define kam_0 0
#define kam_1 1
#define kam_2 2
.
.
.
#define kam_9999 9999


I got a segfault when we are > 4500 defines...crashed; but did not get an error message... Shocked

FWIW...

~Kam (^8*
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 18, 2008 12:20 pm     Reply with quote

As I think it was said earlier in the thread, look for wacky stuff like
accidentally typing a semi-colon at the end of your #define statement.
This can cause weird compiler errors. It happened recently here to
another co-worker here at the company. I had to help him find it.
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

It IS the compiler!
PostPosted: Mon Apr 21, 2008 9:26 am     Reply with quote

First of all, THANKS to all who have helped. All the recommendations are appreciated. Very Happy

Second of all, it appears to be the compiler. Although your suggestions and questions are on topic and intelligent, since I have found a key clue that points to the compiler, I will refrain from answering all of your questions.

If I remark out all of these lines, and only allow ONE to compile at a time, then I get the following results:
Code:
#define KYLE               0x01   // <==Compiles OK
#define LOG                  0x01   // <==Compiles OK
#define LOG_CONDENSATE      0x04   // FAILS!
#define LOG_CONDENSATE      0xFF   // FAILS!
#define CONDENSATE         0x04   // FAILS!
#define LOG_CCSBUG         0xFF   // FAILS!
#define LOG_ASSHAT         0x04   // FAILS!

#define LOG_               0x01   // <==Compiles OK
#define LOG_C               0x01   // FAILS!
#define KYLE_KYLE            0x01   // FAILS!
#define ASSHAT               0x01   // FAILS!

From this, I draw the following conclusions:
    The name is not the problem
    The underscore is not the problem
    The value is not the problem
It almost appears as if the PCH compiler is running out of room for the definition names; at this point any name is okay if it is 4 characters or less.

Quote:
Can you post line 25 to 35 of Atlanta-RTC.c?
Sure, I put it in the initial post:
Code:
fprintf(TERM,"Low battery! (%lu VE2)",m);


Thanks guys,
Kyle
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

Even more bizarre
PostPosted: Mon Apr 21, 2008 9:41 am     Reply with quote

Just found another oddity. As we know, adding this line:
Code:
#define LOG_CONDENSATE      0x04
causes the program not to compile, and report the error on line 31.

However, I just found quite by accident, that if I add an extra line like this:
Code:
#define KYLE               0x01
#define LOG_CONDENSATE      0x04


THAT WORKS! It's like it "covers up" the compiler bug. No idea why. I guess I'll be adding useless defines in the future. Rolling Eyes

Thanks,
Kyle
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: It IS the compiler!
PostPosted: Mon Apr 21, 2008 10:40 am     Reply with quote

kda406 wrote:
Quote:
Can you post line 25 to 35 of Atlanta-RTC.c?
Sure, I put it in the initial post:
Code:
fprintf(TERM,"Low battery! (%lu VE2)",m);
I did not ask for a single line of code but for a range of code lines, this because the CCS compiler often is wrong in pointing out the line where the actual error resides. Your line 31 looks OK, but I'd like to see the 10 lines before and 5 lines after this particular line.
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

PostPosted: Mon Apr 21, 2008 11:33 am     Reply with quote

Sorry about that. I read your request wrong even when I quoted it. Had a rough weekend, and had to come back to work to rest. Wink

Code:
//--------------------------------------------------------------------------
// Do the daily maintenance.  (Expand as necessary)
//
void AtlRTC_Daily(void) {
   int16 m;
   gsTimer.tDaily = gtNow + 86400;      // Set up the daily maintenance for tomorrow
   m = AtlVolt_ReadBatt();               // Get the battery voltage
   if(m < VOLT_BAT_MIN) {               // If it is too low, note the problem
      fprintf(TERM,"Low battery! (%lu VE2)",m);
      AtlTerm_CRLF();
      gsLEDStatus.service = LEDON;
      gbBattLow = true;
   } else {
      gbBattLow = false;
   }
}

I couldn't do 10 lines before because this is the first function in a library.
Thanks,
Kyle
kda406



Joined: 17 Sep 2003
Posts: 97
Location: Atlanta, GA, USA

View user's profile Send private message

PostPosted: Fri Jul 18, 2008 2:52 pm     Reply with quote

I never saw anything about this being fixed in any of the change logs, so I never upgraded. Today I upgraded to 4.076 and now I can add new #define statements. I have been coding without them for months on this project, and it has been painful.

After upgrading to 4.076, I was immediately able to add
Code:
#define LOG_OVERFLOW         0x8F

with no errors. With this release, hopefully we can now close the chapter on the maximum number of defines too.

-Kyle
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group