C2801 Error on Variable Declaration

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

C2801 Error on Variable Declaration

10,092 次查看
TheBroadLea
Contributor I

Below is some Processor Expert-generated code.  I have a CAN bean (MainboardCan) and a PIT bean (MainTimer).  The only change I have made to the code is to add a single int declaration, and the compiler gives me a C2801 error: '}' missing.

/* Including used modules for compiling procedure */#include "Cpu.h"#include "Events.h"#include "MainboardCan.h"#include "MainTimer.h"/* Include shared modules, which are used for whole project */#include "PE_Types.h"#include "PE_Error.h"#include "PE_Const.h"#include "IO_Map.h"void main(void){  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/  PE_low_level_init();  /*** End of Processor Expert internal initialization.                    ***/  /* Write your code here */  int yeldarb;  /* <--------- ERROR C2801 ????  */  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/  for(;;){}  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

Config:

  • CW5.0 for HC08 with patch 1, build 060222
  • PE v2.97.01 with patches 1 & 2
  • Small memory model
  • Chip: MC68HC08AZ32A

FYI, when I change the type to, say, a byte, the compiler throws a C1815 error, telling me that there's no such typedef as byte.  Now, I can right-click on byte, and the editor will take me straight to its typedef in PE_Types.h.  The compiler, however, can't seem to find it.  Pretty flakey.

Any ideas?

Thanks much for your help.

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

2,308 次查看
alex_spotw
Contributor III
Hi:

The problem is trying to define the variable after the call to the a function in the main() function.

If you put


int yeldarb;


before the PE_low_level_init(); , you won't have any problem.

Regards,

Alex.

Message Edited by alex_spotw on 04-11-200610:28 AM

0 项奖励
回复

2,308 次查看
TheBroadLea
Contributor I

Doh!

[sigh]  Forgive the stupid-user question.  I guess I've been working too long in C++ and Java and JavaScript and VB and about any other language out there that doesn't care where you declare something.  I'm so ashamed!

Thanks.  I'll go back to work here with my tail between my legs.

0 项奖励
回复

2,308 次查看
rocco
Senior Contributor II

The Broad Lea wrote:

. . . I'm so ashamed!


Actually, it is Metrowerks that should be ashamed.

First, for not allowing you to put the declarations where you want.

Second, for complaining about it with such a misleading error message.

(just my meaningless opinion)
0 项奖励
回复

2,308 次查看
CrasyCat
Specialist III
Hello
 
In that case Freescale compiler is fully ANSI C compliant.
ANSI C standard does not allow you to define a variable between two instructions
or assignments.
 
Local variable definition are only allowed at the beginning of a block.
 
CrasyCat. 
0 项奖励
回复

2,308 次查看
TheBroadLea
Contributor I
I do have to conceded the point on the ANSI spec.  As I mentioned, I had just forgotten about that constraint in C.  However, the error message could certainly be better, i.e., actually tell me what the problem is instead of handing me this cryptic missing-brace thing.
 
It doesn't matter now.  I know what the problem is, and anybody else who runs into it in the future will have this forum thread.  All's well.
 
Thanks, all.
0 项奖励
回复

2,308 次查看
eJames
Contributor I

"It doesn't matter now.  I know what the problem is, and anybody else who runs into it in the future will have this forum thread."

 

And that would be me. Thank you!

0 项奖励
回复

2,308 次查看
Coderunner
Contributor III

Yeh, I had same annoying problem. I was trying to declare a "byte" type variable in an ISR after assignment statement in ISR. When I moved it to a first line in that ISR it worked! So yes it has to be first item in a block.

0 项奖励
回复

2,308 次查看
hawk
Contributor II

Ok, 2014. I too had the same problem.  Thanks to all on this thread.

0 项奖励
回复