View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
CCS 5.092 - don't "MyStruct x = MakeStruct();" |
Posted: Thu Feb 06, 2020 9:27 am |
|
|
PIC24/5.092/single file.
Just posting this here in case anyone else runs into it. While CCS (and other C compilers) allow:
...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: 19537
|
|
Posted: Thu Feb 06, 2020 12:47 pm |
|
|
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
|
|
Posted: Fri Feb 07, 2020 3:34 am |
|
|
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: 9241 Location: Greensville,Ontario
|
|
Posted: Fri Feb 07, 2020 8:54 am |
|
|
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: 552 Location: Des Moines, Iowa, USA
|
|
Posted: Fri Feb 07, 2020 10:17 am |
|
|
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: 1353
|
|
Posted: Fri Feb 07, 2020 11:53 am |
|
|
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: 19537
|
|
Posted: Fri Feb 07, 2020 1:32 pm |
|
|
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: 552 Location: Des Moines, Iowa, USA
|
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 552 Location: Des Moines, Iowa, USA
|
|
Posted: Mon Feb 24, 2020 11:43 am |
|
|
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 ? |
|
|
|