This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
The items high-lighted below (7 of them) cause Error #28 -- interestingly, they are the only items that are declared as "const char *"
The non-const items seem fine but the compiler is flagging the const strings with
"error #28 expression must have a constant value". All the items in this area are constant items... they are pointers and are all resolved at link time. The only difference I can see is the ones being complained about will reside in code flash. The others land in ram, but I think that the address the items land in should be irrelevant. I've used the same code on IAR and Keil and both of those compilers work fine.
the constant expression "const char * szCompany ="MyCompany"; "
is declared as "extern const char * szCompany" in a header file included by the code below.
the expression "char * szSessionID = "0xxxxx" "
is declared as "extern char * szSessionID"
The const item generates error #28 and the item without const compiles fine. This seems to be a compiler issue. Suggestions?
///////////////////////////////////////////////////////////////////////////////
//
// MSP Get Attributes - Attributes Pointer Table
//
///////////////////////////////////////////////////////////////////////////////
const char* MWP_Attributes_Table[ ATTRIBUTE_ENTRY_COUNT ] =
{
{ NULL }, // spare00
{ &SetMyName[SHORT_NAME_OFFSET] }, // ShortName
{ szCompany }, // VendorName
{ szModel }, // VendorModel
{ szFirmwareRev }, // VendorVersion
{ szPlatform }, // PlatformModel
{ &szHwRevNo[13] }, // HardwareRevision
{ szPlatformRev }, // FirmwareRevision
{ szPlatformDate }, // FirmwareDate
{ &szSerialNo[4] }, // SerialNumber
{ szSessionID }, // SessionId
{ &szPatient[9] }, // PatientId
{ &szDOB[9] }, // PatientDOB
{ szDate }, // SessionDate
{ szTime }, // SessionTime
{ &szOperatingMode[12] }, // SessionType
{ &szRecLength[9] }, // SessionDuration
{ szCableType }, // CableType
{ szLeadText }, // LeadConfiguration
{ &szSampleRate[9] }, // SampleRate
{ &szResolution[11] }, // DataResolution
{ szPackType }, // DataFormat
{ NULL }, // EcgRecordingDuration (Integer in Hours)?
{ NULL }, // spare23
{ NULL }, // spare24
{ NULL }, // spare25
{ NULL }, // spare26
{ NULL }, // spare27
{ NULL }, // spare28
{ NULL }, // spare29
{ NULL }, // spare30
{ NULL } // spare31
};
I can reproduce this diagnostic with the TI MSP430 compiler ...
Normand Martel77 said:"error #28 expression must have a constant value".
But I cannot reproduce this ...
Normand Martel77 said:I've used the same code on IAR and Keil and both of those compilers work fine.
I don't have those compilers. But I do have two different versions of the gcc compiler. And both of them give a similar error the the TI compiler.
I'd appreciate if you would submit an example, source code and build options, which builds clean with the gcc compiler, but fails for the TI compiler.
Thanks and regards,
-George
Normand Martel77 said:Since at compile/link time these values resolve, it should have worked.
The expression must be a constant expression at compile time, and the pointer form is not. This is not a flaw in the compiler, it's just how the C language works.
Just to close the loop on this.... I Did declare my variables as CONST. I didn't want them to be modifiable and further, since I am using a microcontroller I wanted the strings stored in flash (.text).
This form fails:
const char szCompany[] = "MyCompany";
This form works:
const char *szCompany = "MyCompany";
In my opinion, both forms should work.