Error in a conversion from 'const char *'  to 'char *'

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error in a conversion from 'const char *'  to 'char *'

7,773 Views
jballes
Contributor II
Hi,

I am having a compilation problem with the command line tools of CodeWarrior for Coldfire.

The compiler version that I am using is the following.

CodeWarrior C/C++ for ColdFire.
Copyright (c) 2006, Freescale Semiconductor, Inc
All rights reserved.
Version 6.3 build 4
Runtime Built: Jul 12 2006 11:07:57

(With version 6.4 build 5 I also have the same issue).

The problem is that the compiler stops with a the following error "illegal implicit conversion from 'const char *' to 'char *'".

This conversion comes from an autogenerated code that I cannot control, so I need to add the right flag in CodeWarrior to avoid the error.

However, I have tried the following flags with no success:

- -nofail
- -w off
- -w noerror, noiserror
- -w nopedantic
- -pragma "no_conststringconv off"
- -ansi off
- -strict off

None of them works and I am stuck.

I send you a sample of the command used:

mwccmcf -c -strict off -nodefaults -msgstyle gcc -gccinc -ppopt line,full,space -g -model far -abi compact -proc MCF5282 TTest_aug.c -o TTest.o

And a sample of the output...

cwarrior_coldfire_t32_common\TTest_aug.c:2756: illegal implicit conversion from 'const char *' to
cwarrior_coldfire_t32_common\TTest_aug.c:2756: 'char *'
cwarrior_coldfire_t32_common\TTest.c:284: note: (corresponding #line reference)

Any ideas?

Thanks in advance,

Javier Ballesteros
Labels (1)
0 Kudos
8 Replies

3,354 Views
CompilerGuru
NXP Employee
NXP Employee
Well, I guess the answer: get your generation tool to generate const correct code does not help Smiley Wink.

I tried, and for code like:
void fun(char*);

int main()
{
 const char* a="";
 fun(a);
 while(1) {}

 return 0;
}

I did get this message. The only workaround I did find for now (did not dig deep) was to enable gcc extensions. Looks like gcc is less picky in this case.
Option "-gccext on"

Daniel
0 Kudos

3,354 Views
jballes
Contributor II
Daniel and CrasyCat, you are both right, it works, both the pragma (the tool is flexible enough to let me add pragmas in its generated code, :smileyhappy: ) and the flag.

Right now they have all become warnings.

However, it still does not compile... I've noticed that between the list of warnings there are two errors:

cwarrior_coldfire_t32_common\TTest_aug.c:2953: illegal implicit conversion from 'struct *' to
cwarrior_coldfire_t32_common\TTest_aug.c:2953: 'struct *'
cwarrior_coldfire_t32_common\TTest.c:481: note: (corresponding #line reference)

I think that CodeWarrior is too pedantic. Any more ideas?

Thanks!

Javier

PS: I know that the code must be correct because it is a generated code by Rational TestRT.

Message Edited by jballes on 2007-04-0204:26 PM

0 Kudos

3,354 Views
CompilerGuru
NXP Employee
NXP Employee
Can you extract and provide a complete compilable (or actually not compiling) snippet?
Given the error message there are two nameless structs involved, but without more information about the actual case it is hard to tell where the problem is from, and which party is right.
That a "Rational TestRT" is generating the code does not make it correct, I only would accept this for a tool provided by the ANSI-C committee :smileyhappy:.
Some compilers are more strict, and actually I did not take our CF to be especially picky in its default setup. I always make it more strict by enabling some additional warnings.

Daniel

BTW: You get an incompatibility diagnostic between two different C files? Usually a single compilation unit only consists of one C file and then the compiler has no chance to issue such inconsistencies. But of course including C files is legal, just not usual.
0 Kudos

3,354 Views
jballes
Contributor II
Daniel,

Thanks again for your answer. I agree with you in the point that maybe the generated code is not purely ANSI C compatible :smileyhappy: What I meant is that it is correct in the core, but maybe not in the structure.

Anyway, I have investigated what Test RT does and I have created a single code reproducing the errors that I have at the moment:

Code:
typedef struct {
  unsigned long FirstCluster;
  unsigned long FilePos;
  unsigned long size;
  signed short Error;
  unsigned char InUse;
  unsigned char AccessFlags;
  union {
    struct {
      int first;
      int second;
      int third;
    } Fat;
  } Data;
} FS_FILE;


int a (
 struct {
  int val1;
  int val2;
 } *p
 )
{
}

int b( struct {
  int val1bis;
  int val2bis;
 } *pbis
 )
{
 a(pbis);  /* Error " illegal implicit conversion from 'struct  *' to 'struct *' " */
}

int c ( union {
  struct {
   int first;
   int second;
   int third;
  } Fat;
 } *mem)
{

}

int d (FS_FILE *file)
{

 c(&(file->Data)); /* Error " illegal implicit conversion from 'union  *' to 'union  *' " */
}

 
This code compiles perfectly with no need for external includes.

As you can see, TestRT defines structs un unions and it respects exactly the same structure while performing the calls, but it uses no typedef.

I hope that this will let you find the flag! :smileyhappy:

Kind regards,

Javier

Message Edited by jballes on 2007-04-0309:35 AM

0 Kudos

3,354 Views
CompilerGuru
NXP Employee
NXP Employee
check this pdf: "C:\Program Files\Freescale\CodeWarrior for ColdFire V6.3\Help\PDF\ColdFire_Build_Tools_Reference.pdf" It contains a "#pragma mpwc_relax on"/-relax_pointers entry which lets your code compile. Apart from that it will work this way, I don't think your snippet is ANSI-C compliant, I wonder if there is no switch somewhere in your generation tool to get code which uses properly declared types. Daniel BTW, MSVC 6.0 (a really old version) did issue the same diagnostics as CW, just by default as warnings, not as error.
0 Kudos

3,202 Views
sundar19
Contributor III

Can you please tell me how to do it? 

 

void ProcessCAN(void)
{
can_msg_struct msgCanRX;

if (CanRxMbFull(0) == 1) /* Check if CAN message received */
{
msgCanRX = CanRxMsg(0); // Receive CAN message 
UartTxMsg((unsigned char *)msgCanRX.data[0], 1);//  print received data byte in serial monitor
}
}

 

All I want is to display received CAN data in serial terminal , I use mpc5606b startertrak dev kit and code warrior. I get garbage vales when I use this method to display values. Is this related to data type issue? 

 

void UartTxMsg(uint8_t *u8TxData, uint32_t u32Size)

 

As UART transmitter considers its data to be in uint8_t , but my CAN data is unsigned char 

Thank you

Tags (2)
0 Kudos

3,354 Views
jballes
Contributor II
It works perfectly! All errors have become warnings right now!

Thanks a lot for your reactivity Daniel and CrasyCat!!

Kind regards,

Javier
0 Kudos

3,354 Views
CrasyCat
Specialist III
Hello
 
You may want to try to enables GCC C language extensions while building your code.
 
In this purpose use option -gccext or #pragma gcc_extensions on.
 
This may do the trick.
 
CrasyCat
0 Kudos