Assembler error in GCC: Error: byte or halfword not valid fo

Just in case anyone else gets this error:

It’s caused by a code like this:

typedef struct {u32 myU32;} TMyRecord;

void myfunc()
 {
  TMyRecord myrec;
  int myptr;
  char c;
  ...
  ((char *)(&myrec.myU32))[myptr]=c;
 }

I’m not sure what’s wrong with the last line but it’s causing the problem, when compiled with gcc/OAT 3.01. It works fine in gcc/OAT 4.20. Creating a temporary variable fixes the problem:

char *pc=((char *)(&myrec.myU32));
  pc[myptr]=c;

Milan

Hi Milan,

I had exactly the same problem.

Please see: http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?t=76

The only thing that helped was to rewrite the code that caused it. This must be some bug in gcc because with the ADS compiler my code that caused the problem worked perfectly!

Best Regards,
Jan

Compiler errors are rare but they happen.
Maybe you can see if you can upgrade GCC in your 3.01 install using the cygwin installer?

Personally I have only used ARM ADS for all my projects and never had problems with the compiler. (Is there any support in the wavecom sdk’s for the newer ARM compiler offerings? I don’t think we’re too likely to upgrade considering the costs, but it’s still nice to know.)

Sorry for a stupid question but I can’t get what this code is supposed to do.

typedef struct {u32 myU32;} TMyRecord;

void myfunc()
 {
  TMyRecord myrec;
  int myptr;
  char c;
  ...
  ((char *)(&myrec.myU32))[myptr]=c;
 }

Here you cast a pointer to a char. Compiler removes 3 senior bytes from the pointer and puts the value in a temporary variable that exists as long as assigment is going on. Then you assign c char to the temporarry variable. As the assigment is over the temporrary variable is destroyed. What’s the point?

The compiler stores the temporarry variable in a register, thats where your compile error shows up.

char *pc=((char *)(&myrec.myU32));
pc[myptr]=c;

Here you store result of casting pointer to char in your variable and right after that assign the variable to another value. What’s the point?

Are you familiar with the difference between char and char *? This code should:

  1. take the pointer to myrec.myU32
  2. change the type to a pointer to a char but keeping the full address
  3. add myptr to the address
  4. store c on that address.

No way. It’s char * going on.

Same as before, but first line does steps 1+2 and the second does steps 3+4.

Milan