|
|
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 617 Location: Des Moines, Iowa, USA
|
CCSC.exe/CCSCOMPILE.exe passing in #defines as quoted string |
Posted: Thu Jan 30, 2025 4:57 pm |
|
|
When command line compiling, the manual says you can use
...to set a global define. We use this and it works, for lables, numbers and even single quoted characters:
Code: | #BOARD=CONTROL #DEBUG=1 PARTITION='A' |
But I had wanted to pass in something like this...
Code: | #if !defined(VERSION_METADATA)
#define VERSION_METADATA "-Bootloader"
#endif |
But trying to do
Code: | #VERSION_METADATA="-OtherThing" |
...does not work. It is passed in without quotes around it and just creates a compile error.
The manual also lists an alternative:
...but that does the same thing. Actually, it's a bit different. It I try to pass in "-Bootloader" using #, it effectively ends up like:
Code: | #define VERSION_METADATA -Bootloader |
...with no quotes around it. Using the +GVERSION_METADATA="-Bootloader" will end up in UPPERCASE like:
Code: | #define VERSION_METADATA -BOOTLOADER |
I have no idea why.
The usual escapes like \"String\" do not work.
Support said double quotes should work, but they do not.
Anyone figured out how to do this? _________________ 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 ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 617 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Jan 30, 2025 4:58 pm |
|
|
Also, order on the compile line seems to matter. You can have them before the BUILD=, but when I put one after it I got weird compiler errors. _________________ 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 ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19649
|
|
Posted: Fri Jan 31, 2025 3:07 am |
|
|
OK. I think this is probably Windows. I know on an older compiler I was using,
what you had to do, was escape the required inverted commas.
So possibly something like:
#xxx="^"yyy^""
The inverted commas have a special meaning to the Windows shell, so you
have to put extra ones inside the ones telling the shell to take the
contents as an argument, and then escape these with a caret, to tell tke
shell not to remove them.
Haven't tried it, but suspect this is what might be needed. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1365
|
|
Posted: Fri Jan 31, 2025 9:21 am |
|
|
If you can't figure out how to escape the quotes, you can try a work around using precompiler stringification:
Code: |
#define NAME_STR(x) #x
#define VALUE_STR(x) NAME_STR(x)
#if defined(VERSION_METADATA)
#define VERSION_METADATA_STR VALUE_STR(VERSION_METADATA)
#else
#define VERSION_METADATA_STR "-Bootloader"
#endif
|
Then you use VERSION_METADATA_STR in your code. the VALUE_STR() macro will add quotes around the value of whatever is passed in
I don't have a setup here to test, but maybe you can get something like that to work. A lot of it will depend on how the shell that you are using passes in the value to the compiler.
REF: https://gcc.gnu.org/onlinedocs/gcc-4.3.6/cpp/Stringification.html |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 617 Location: Des Moines, Iowa, USA
|
|
Posted: Fri Jan 31, 2025 9:04 pm |
|
|
Ttelmah wrote: | OK. I think this is probably Windows. I know on an older compiler I was using,
what you had to do, was escape the required inverted commas.
So possibly something like:
#xxx="^"yyy^""
The inverted commas have a special meaning to the Windows shell, so you
have to put extra ones inside the ones telling the shell to take the
contents as an argument, and then escape these with a caret, to tell tke
shell not to remove them.
Haven't tried it, but suspect this is what might be needed. |
No luck there. That just turns into
#define TEST=^Hello^
Interesting that it strips out both sets of quotes. _________________ 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 ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 617 Location: Des Moines, Iowa, USA
|
|
Posted: Fri Jan 31, 2025 9:07 pm |
|
|
[quote="jeremiah"]If you can't figure out how to escape the quotes, you can try a work around using precompiler stringification:[/code]
That's a cool workaround. I've been playing with C since the late 1980s (back in the K&R compiler days) and only learned of this stringification about a year or so ago. I wanted to change a #define in my version metadata based on if I had build the binary with debug enabled, and printf, and came up with something like this mess:
Code: | // So our metadata string reflects what we are building:
#if (DEBUGGER_ON > 0)
#define STR_DEBUG "-debug"
#else
#define STR_DEBUG ""
#endif
// These macros turn a defined number into a quoted string so we
// can use them here. See:
// https://stackoverflow.com/questions/22320619/how-do-i-concatenate-define-value
#define mkstrX(s) #s
#define mkstr(s) mkstrX(s)
#if (PRINTF_SUPPORT > 0)
#define STR_PRINTF "-printf"
#else
#define STR_PRINTF ""
#endif
// Define combined metadata string.
#define VERSION_METADATA_STRING VERSION_METADATA STR_DEBUG STR_PRINTF |
I completely forgot this was a thing. That's a nice workaround. Thanks! _________________ 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 ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 617 Location: Des Moines, Iowa, USA
|
|
Posted: Fri Jan 31, 2025 9:30 pm |
|
|
Using the Online GDB compiler, I did tests of all the various things CoPilot was suggesting. None of them worked with CCS, but one works with GCC.
TEST=\"This Works\"
Test program: https://onlinegdb.com/ZmTHpKyYN _________________ 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 ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19649
|
|
Posted: Sat Feb 01, 2025 3:24 am |
|
|
At least you have a workaround.
It is down to what shell you are actually using, and what it accepts as an
escape. The caret was the escape for the old Windows command shell
Backslash is used by some, etc. etc.. Your shell is ignoring the caret,
so deletes both sets of inverted commas. It looks as if your shell accepts
backslash, but then CCS is not parsing the inverted commas as required.
This part you might query with CCS.
The behaviour depends on both the behaviour of the shell, and the
program being called. You have a fix now for the shell, unfortunately it
looks as if CCS did not consider this possibility (probably because they
'knew' that the shell didn't allow inverted commas to be easily passed). |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 617 Location: Des Moines, Iowa, USA
|
|
Posted: Sat Feb 01, 2025 12:53 pm |
|
|
Yeah, just using Windows command prompt. I'm not sure what else they would design their command lines tools for Windows to run in. But it may have to do with the language their compiler was written in, since it may be doing its own parsing of the command line. _________________ 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 ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1365
|
|
Posted: Sat Feb 01, 2025 1:37 pm |
|
|
allenhuffman wrote: | Yeah, just using Windows command prompt. I'm not sure what else they would design their command lines tools for Windows to run in. But it may have to do with the language their compiler was written in, since it may be doing its own parsing of the command line. |
There's about 5 different common command line tools for windows I can think of offhand, so it might be something not everyone expects. It could also be that they never looked at inputs that need to be strings (most defines tend to be numbers), so it may not hurt tossing them a call/email and asking about it too. Maybe they can improve it or have a secret escape code. |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 617 Location: Des Moines, Iowa, USA
|
|
Posted: Sat Feb 01, 2025 3:21 pm |
|
|
jeremiah wrote: |
There's about 5 different common command line tools for windows I can think of offhand, so it might be something not everyone expects. It could also be that they never looked at inputs that need to be strings (most defines tend to be numbers), so it may not hurt tossing them a call/email and asking about it too. Maybe they can improve it or have a secret escape code. |
It’s one of several tickets I have with them now. They gave me two solutions and neither worked. Still waiting. They did send me a ccscompile to fix error return codes. _________________ 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 ?
Using: 24FJ256GA106, 24EP256GP202 and 24FJ64GA002. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1365
|
|
Posted: Sat Feb 01, 2025 9:54 pm |
|
|
allenhuffman wrote: |
It’s one of several tickets I have with them now. They gave me two solutions and neither worked. Still waiting. They did send me a ccscompile to fix error return codes. |
For what it is worth, when I tried to play with this and set my external defines via the project options and I noticed that if I wrapped it there in quotations that it replaced the quotation marks with \" instead, so they are definitely trying to do some kind of escape sequence. I didn't nail down a good solution though. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19649
|
|
Posted: Sun Feb 02, 2025 4:12 am |
|
|
The paint is the handling of inverted commas, is done by the shell not CCS.
It is standard in all the various Windows shells to automatically delete
inverted command, and pass what it inside them as a parameter to the
called program. Actually as a string!.
Now that is why using the \ escape worked for GCC.
The problem now is that because of this CCS never considered that
somebody might want or try to pass a string parameter, using escapes.
So now their code does not handle this.
What they in fact do, is take the value passed (which is a string), and then
just use ATOI to convert this to a number,
As you say Jeremiah, most people would not want this.
What they will have to do, is add a test to see if the leading character
passed to them is a pair of inverted commas, and if it is then create a string
define, instead of using ATOI.
The other way would be for then to add another rfunction ##xxx="string",
and then simply treat the value passed here as a string define. I actually
think this would be the better and simpler way to go. |
|
|
|
|
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
|