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

CCS 5.092 - don't "MyStruct x = MakeStruct();"

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



Joined: 17 Jun 2019
Posts: 551
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

CCS 5.092 - don't "MyStruct x = MakeStruct();"
PostPosted: Thu Feb 06, 2020 9:27 am     Reply with quote

PIC24/5.092/single file.

Just posting this here in case anyone else runs into it. While CCS (and other C compilers) allow:
Code:
int x = foo();

...where foo() is something that returns an int, this currently does not work on CCS if it's a structure:
Code:
MyStruct x = makeStruct();

You have to split it up to get it to compile:
Code:
MyStruct x;
x = makeStruct();

We expect it's related to some other issues with structures we've found lately. This info has been sent to CCS.

Simple demo:
Code:
#include <main.h>

typedef struct
{
   int width, height;
} SizeStruct;

SizeStruct MakeSize(int width, int height)
{
   SizeStruct temp;
   
   temp.width = width;
   temp.height = height;
   
   return temp;
}

void main()
{
/*
      // Works:
      SizeStruct size;
      size = MakeSize(10, 20);
*/ 
   // Does not compile:
   SizeStruct size = MakeSize(10, 20);
 
   while(TRUE)
   {
      //TODO: User Code
   }
}

// End of main.c

_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19492

View user's profile Send private message

PostPosted: Thu Feb 06, 2020 12:47 pm     Reply with quote

CCS does not actually 'like' in code type declarations. Historically this
was not allowed in C (declarations could only be at the start of code
sections), and support was only added recently and is limited.
Personally I keep to the C standard and never declare in line.
ralph79



Joined: 29 Aug 2007
Posts: 87

View user's profile Send private message

PostPosted: Fri Feb 07, 2020 3:34 am     Reply with quote

Personally, I think the best method for not having problems is to code strict "C". Even the declaration of a simple loop variable, I do always in the begining of the function. I had also in the past (couple of years ago) very strange behavior when I did something like:
Code:

for (int8 i = 0; i < 10; i++)
{
   // TODO
}
temtronic



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

View user's profile Send private message

PostPosted: Fri Feb 07, 2020 8:54 am     Reply with quote

One thing to keep in mind is that the compiler is 'evolving' over the decades. It was never a 100% by the book, official 'ANSI C' compiler. Rather 'C' geared towards PICs like the 16C84. A LOT of features have been added to take advantage of the 100s of PIC types that popup, almost on a daily basis!
How CCS figures this out is beyond me, then again I'm from the era where I could read 7bit ASCII paper tapes.
allenhuffman



Joined: 17 Jun 2019
Posts: 551
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Feb 07, 2020 10:17 am     Reply with quote

Agreed. I strive for 100% ANSI portable code. Unfortunately, that doesn't work well in alot of embedded compilers. At a previous job, the tool we used (either Renesys or whatever we used for TI MSP430) would fail on a constant string if it was longer than 80 characters (with a very cryptic error message; we had to go through support to understand what the issue was). It's not an isolated thing for CCS, for sure.

I tend to flesh out my program logic in another compiler (even if it's GCC with all the warnings and such turned on).

Not sure this is of interest to anyone else here, but there's a document showing the ANSI things in the CCS PIC compilers:

https://www.ccsinfo.com/downloads/ansi_compliance.pdf
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
jeremiah



Joined: 20 Jul 2010
Posts: 1344

View user's profile Send private message

PostPosted: Fri Feb 07, 2020 11:53 am     Reply with quote

I looked at the C89 standard (the one CCS lists on its PDF) section 6.7.8 (Initialization) and initialization by function is not listed as a valid initializer for a variable as far as I can see. None of the syntax breakdowns mention functions and none of the examples do either. Anyone else want to take a look and see if it is valid C89 or if it is just a common extension among other compilers?

I can't point you to the actual standard (paywalled) if you don't already have it. Here is the last draft of it if you don't have the actual: http://www.open-std.org/JTC1/sc22/wg14/www/docs/n1256.pdf
Ttelmah



Joined: 11 Mar 2010
Posts: 19492

View user's profile Send private message

PostPosted: Fri Feb 07, 2020 1:32 pm     Reply with quote

CCS is actually very close to supporting C89. Probably about 98% fit, What
it doesn't support is lot of the later extensions.
Primarily is C as described in K&R 1st edition. For this is is now a 99.9%
'fit'.
Keep this in mind, and code to this, and it runs excellently.
allenhuffman



Joined: 17 Jun 2019
Posts: 551
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Feb 12, 2020 3:40 pm     Reply with quote

CCS reports this issue will be fixed in the next release (currently broken in 5.092).
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
allenhuffman



Joined: 17 Jun 2019
Posts: 551
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 24, 2020 11:43 am     Reply with quote

5.093 has been released. I have confirmed it fixes this issue.

Quote:
5.093 Fixed an compile time error for some structure initializations when the structure was returned from a function

_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
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