benmargolin / protobuf-embedded-c

Automatically exported from code.google.com/p/protobuf-embedded-c
0 stars 0 forks source link

Code doesn't compile with most other C compilers than gcc. Declaring variables after code statements not standard C #21

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile generated code with Texas tms470 compiler. 
2.
3.

What is the expected output? What do you see instead?
I exepect the code to compile, same as with gcc. But since some genereted 
functions have variables declared after code statements, one gets compilation 
errors. 

What version of the product are you using? On what operating system?
1.0M2. 

Please provide any additional information below.

The code below is an example from the .stg file that does not generate code 
that compile with a lot of compilers:

static int read_raw_little_endian32(int *tag, void *_buffer, int offset) {
    offset = read_raw_byte((char *)tag, _buffer, offset);
    char b1 = (char) *tag;
    offset = read_raw_byte((char *)tag, _buffer, offset);
    char b2 = (char) *tag;
    offset = read_raw_byte((char *)tag, _buffer, offset);
    char b3 = (char) *tag;
    offset = read_raw_byte((char *)tag, _buffer, offset);
    char b4 = (char) *tag;

Change it to this instead and it compiles:

static int read_raw_little_endian32(int *tag, void *_buffer, int offset) {
    char b1;
    char b2;
    char b3;
    char b4;
    offset = read_raw_byte((char *)tag, _buffer, offset);
    b1 = (char) *tag;
    offset = read_raw_byte((char *)tag, _buffer, offset);
    b2 = (char) *tag;
    offset = read_raw_byte((char *)tag, _buffer, offset);
    b3 = (char) *tag;
    offset = read_raw_byte((char *)tag, _buffer, offset);
    b4 = (char) *tag;

Same thing in a few more places as well...

Original issue reported on code.google.com by anderssa...@yahoo.se on 28 Dec 2012 at 8:24

GoogleCodeExporter commented 9 years ago
This could be another motivation for switching from StringTemplate to a 
"self-written" generator.

Original comment by wolfgang.schwitzer on 22 Feb 2013 at 11:18

GoogleCodeExporter commented 9 years ago
"Code doesn't compile with most other C compilers than gcc. Declaring variables 
after code statements not standard C"
This code complies with the C-standard C99, see 
http://en.wikipedia.org/wiki/C99. You can compile this code with every C99 
capable c-compiler, it is not gcc specific.

Original comment by embedded...@gmail.com on 1 Mar 2013 at 8:22

GoogleCodeExporter commented 9 years ago
Issue 31 has been merged into this issue.

Original comment by wolfgang.schwitzer on 13 Mar 2013 at 11:45

GoogleCodeExporter commented 9 years ago

Original comment by nvp...@gmail.com on 31 May 2013 at 8:37