CodeWarrior for StarCore V3.0 - array initialization

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

CodeWarrior for StarCore V3.0 - array initialization

2,584 次查看
jogging
Contributor I
Hi,everyone
  recently, I find CW for starcore 3.0 does not support initialization of arrays with variables, which requires
constant. Other compiles such as Visual C++ from Microsoft supports this function. I don't know how the
C standard specify this, but this function is not very difficulty to implement. If this function is supported
in the next release, it can avoid changing codes when we port codes from one compiler to another. Any comments?

Best Regards
Jogging Song

Message Edited by CrasyCat on 2007-04-10 11:04 AM

标签 (1)
标记 (1)
0 项奖励
回复
3 回复数

365 次查看
CrasyCat
Specialist III
Hello
 
Can you please be more specific.
What is not working?
 
Can you provide a code snippet?
 
CrasyCat
0 项奖励
回复

365 次查看
jogging
Contributor I
Hi, CrasyCat
   Following is an example,
   int a, b;
   int arr[] =
   {
      a, b
   };
The example is just an example.

CW tells me: illegal constant expression. C compiles doesn't support to initialize arrays using variables,
it requires programmer to use constant to initialize arrays.

By the way,
I can't find materails about SC3400's instruction set on the websites. Now I need to write assemble code for MSC8144,so instruction set is necessary. Is it available now?

Thanks
Best Regards
Jogging Song
0 项奖励
回复

365 次查看
CompilerGuru
NXP Employee
NXP Employee
That code snippet is not legal in ANSI C 89.
It is legal in C++, and when using C++ the starcore compiler does accept it, so the point is not if it is difficult to implement (I would actually say so, but its done already), but what the language supports. That other compilers do support this as C language extension does not change the language :smileywink:.
If you want to use C, I would suggest that you adapt your source code. I'm sure MSVC will still compile it. Using C++ just for global initialization seems a bit too much for me.

Daniel

PS: I did not check C99, not sure what is supported in this C dialect.

PPS: Does a/b really has to be a variable? I wonder what the real code is using the global initializatioSubmit Postn for.
(Not tested:smileyhappy:
  enum {a=0, b=0};
   int arr[] =
   {
      a, b
   };

0 项奖励
回复