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 CCS Technical Support

Variable that is incremented each time the source is compile

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



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

Variable that is incremented each time the source is compile
PostPosted: Wed Feb 15, 2017 7:38 pm     Reply with quote

The question is there a way to increment a variable in the source each time the source is compiled?
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Thu Feb 16, 2017 4:35 am     Reply with quote

If you are using the CCS IDE then yes there is. I am not sure if this will work with MPLab or the command line tools.

Code:

int16 My_Build_Number = __BUILDCOUNT__;


__BUILDCOUNT__ is defined by the IDE and incremented at every compile by the CCS IDE, but ONLY if global defines are enabled in the project options.

The value is part of the IDE's project file, so if the project is compiled on different PCs, each will have a different build number. As MPLab uses it's own project file, I think this probably won't work in MPLab.
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Thu Feb 16, 2017 4:20 pm     Reply with quote

Compiler: 5.026
Device: PIC24EP512GP806

That's actually something I've always wanted to have but never got to the point of asking for it....

I've opened-up Project > Project Options > Global Defines then I have an 'Enabled' checkbox, a Load, Save and Clear button.

So now how does this thing work? How do you add the __BUILDCOUNT__ define in here?

Providing the necessarry steps in order to accomplish this would be greatly appreciated!

Thanks!

Ben
Tom-H-PIC



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

PostPosted: Thu Feb 16, 2017 8:01 pm     Reply with quote

First thank you RF_Developer

All I did was to enable the Global Defines in Project Options > Global Defines and save.
Then I put RF_Developer code in my h file close to the top.
Compiled and programed the PIC and looked at variable by output it to the serial port.
Work like a champ.
Ttelmah



Joined: 11 Mar 2010
Posts: 19491

View user's profile Send private message

PostPosted: Fri Feb 17, 2017 2:05 am     Reply with quote

benoitstjean wrote:
Compiler: 5.026
Device: PIC24EP512GP806

That's actually something I've always wanted to have but never got to the point of asking for it....

I've opened-up Project > Project Options > Global Defines then I have an 'Enabled' checkbox, a Load, Save and Clear button.

So now how does this thing work? How do you add the __BUILDCOUNT__ define in here?

Providing the necessarry steps in order to accomplish this would be greatly appreciated!

Thanks!

Ben


__BUILDCOUNT__ is a compiler defined 'define'.
The Global Defines option allows the defines in the table below _and some the compiler automatically generates_ to automatically be added to the project. BUILDCOUNT is one of the latter.
So you need do nothing else than have the option enabled. Smile

It's actually being generated by the compiler (not the IDE). If you compile from the command line it also works, provided you have the +G option in the command line.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Fri Feb 17, 2017 5:09 am     Reply with quote

Ttelmah wrote:

__BUILDCOUNT__ is a compiler defined 'define'.

It's actually being generated by the compiler (not the IDE). If you compile from the command line it also works, provided you have the +G option in the command line.


Unfortunately I doubt that will work as people might be expecting. Yes, __BUILDCOUNT__ is defined by the compiler, but the value is managed, and presumably incremented by the IDE. It is certainly stored in the IDE ccspjt file:

Code:

[defines]
buildcount=588
enabled=1
chip=1
D1=
V1=


It also turns out that this value is the next one to be used, i.e. it has been incremented from the last compile. I.e. my last build was 587.

The value has to be stored somewhere. There has to be some file with it in so that it can be incremented. That file appears to be the ccspjt file, and as far as I understand it, that's not involved in command line compilation. I suspect you'll get the same value for every command line compile as there is no way of stroing it from one compile to the next.
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Fri Mar 03, 2017 7:45 am     Reply with quote

Compiler: 5.026
Device: PIC24EP512GP806

Guys,

So if there's one for build count, is there one also for the date and time?

Or how would I go about having incremental versions everytime I compile, other than only the buildcount, without having to do it manually?

Otherwise I could always use the buildcount only.

Thanks,

Ben


[EDIT] I enabled global defines in PROJECT->PROJECT OPTIONS and simply hit APPLY. When I compile with an extra printf statement so that I see the buildcount, I get *** Error 12 [filename] Line 302(122,132): Undefined identifier buildcount

Then I went back in the options and just for the kick, I added __BUILDCOUNT__ as an 'identifier' and hit APPLY. This time, it is telling me *** Error 116 [filename] Line 302(120,121): Printf variable count (%) does not match actual count ::

Inside the ccspjt file, it is called <buildcount> rather than __BUILDCOUNT__ so I tried that as well and same problems.

So how to you actually use this?


Last edited by benoitstjean on Fri Mar 03, 2017 7:58 am; edited 1 time in total
jeremiah



Joined: 20 Jul 2010
Posts: 1344

View user's profile Send private message

PostPosted: Fri Mar 03, 2017 7:52 am     Reply with quote

There are lots of predefined constants and macros for those type of things. Off the top of my head, I want to say __DATE__ and __TIME__, but check the compiler manual. It lists them all. I definitely recommend taking some time and reviewing it. You may find features you need that you didn't know you had available.
temtronic



Joined: 01 Jul 2010
Posts: 9220
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 03, 2017 7:53 am     Reply with quote

Maybe this can be used, from the manual?
...
This pre-processor identifier is replaced at compile time with the time of the compile in the form: "hh:mm:ss"
printf("Software was compiled on ");
printf(__TIME__);
...

There's also one for __DATE__


Jay
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Fri Mar 03, 2017 8:01 am     Reply with quote

This is my line:

fprintf( SERIAL_MONITOR, "\n\r[Starting -- build no. %lu on %lu %lu]", __BUILDCOUNT__, __DATE__, __TIME__ );

Ben

[EDIT] Just realized that __DATE__ and __TIME__ are strings. That works. But buildcount still isn't recognized. Is it supported in 5.026?
temtronic



Joined: 01 Jul 2010
Posts: 9220
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 03, 2017 9:07 am     Reply with quote

from the net....somewhere...

5.027 Added __BUILDCOUNT__ id when global defines are enabled

maybe time to contact CCS ??

Jay
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Fri Mar 03, 2017 9:10 am     Reply with quote

hehe... well I have compiler 5.069 but for the last week, until I reverted back to 5.026, I had just problems after problems.

Maybe I will re-install and try it again.

Thanks!

Benoit
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