CodeWarrior for HC12 version 5.2 does not comply to C90

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

CodeWarrior for HC12 version 5.2 does not comply to C90

2,127 Views
robertobagnara
Contributor I

Compiling the following snippet, say, included in source file r.c:

        int a[sizeof(char) == 2 ? -1 : 1];

with a command like

        "C:\Program Files (x86)\Freescale\CWS12v5.2\Prog\chc12.exe" -Tc2s2 r.c

shows that the compiler violates C90 as far as the very important clause 6.3.3.4 is concerned, where it says:

        When applied to an operand that has type char. unsigned char. or signed char. (or a qualified version thereof) the result is 1.

Is this a known bug?

0 Kudos
Reply
3 Replies

2,007 Views
kef2
Senior Contributor V
  • shows that the compiler violates C90 as far as the very important clause 6.3.3.4 is concerned, where it says:

 

  •         When applied to an operand that has type char. unsigned char. or signed char. (or a qualified version thereof) the result is 1.

It also says

The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type.

Bytes, not chars. And both clauses about sizeof kind of forbid option to make char wider than minimum addressable piece of memory (8bits byte on S12(X), 16bits byte on TI's C2000).

0 Kudos
Reply

2,007 Views
robertobagnara
Contributor I

Hi Jun Zhang.

You probably missed the -Tc2s2  option on the command line. This sets the size of both chars and shorts to 16 bits.  The option is described in the manual in section "-T: Flexible Type Management".  Figure 5.4 in the same manual explains how to set this in the IDE.  The bug in the compiler manifests itself only if the size of chars is set to anything different from 8 bits.

Kind regards,

   Roberto

0 Kudos
Reply

2,006 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Roberto Bagnara 

I tested your code on my side, there is neither build error nor debug error. see attached video.

please create a new project with IDE and test it also.


Have a great day,
Jun Zhang

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply