#813 problem with assignment expressions

closed-fixed
5
2013-05-25
2004-09-17
No

When compiling this small program:

foo() {
int i;
(int)i = 0;
}

sdcc emits this error message:

test.c:3: syntax error: token -> '=' ; column 8
-:0: error: code not generated for 'foo' due to
previous errors
-:0: warning: in function foo unreferenced local
variable : 'i'

It compiles without warnings with gcc 3.2.2. The
syntax error can be fixed by adding a unary '+', but
it still doesn't compile:

foo() {
int i;
+(int)i = 0;
}

test.c:3: error: 'lvalue' required for 'assignment'
operation.
test.c:3: error: code not generated for 'foo' due
to previous errors

Actually, even without the cast, there is a problem
with the unary '+':

foo() {
int i;
+i = 0;
}

test.c:3: error: 'lvalue' required for 'assignment'
operation.
test.c:3: error: code not generated for 'foo' due
to previous errors

These examples were compiled with

SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.4.0 (Feb 23 2004) (UNIX)

Discussion

  • jonathan

    jonathan - 2004-09-17

    Logged In: YES
    user_id=717087

    i'm not a developer here but this will be better to said what is
    your command line to know where could be the problem.

    Have you try it with the last snapshot ?

    regards

    Jonathan

     
  • Erik Petrich

    Erik Petrich - 2004-09-18
    • labels: --> C-Front End
    • assigned_to: nobody --> epetrich
     
  • Erik Petrich

    Erik Petrich - 2004-09-18

    Logged In: YES
    user_id=635249

    This is not valid C; gcc supports this syntax as an
    extension. If you force gcc to strict ANSI C operation, it
    will complain too:

    gcc -ansi -pedantic test.c
    test.c: In function `foo':
    test.c:3: invalid lvalue in assignment

    A request for enhancement has already been made to support
    this extension in sdcc. If you would like to be notified of
    if/when this is implemented, go to the following URL and
    click on the "Monitor" button near the top of the page:

    http://sourceforge.net/tracker/index.php?func=detail&aid=905167&group_id=599&atid=350599

    I am leaving this bug report open because there is still a
    minor bug in sdcc here: it should have given an "'lvalue'
    required for 'assignment' operation" error in the first
    example rather than a syntax error.

     
  • Erik Petrich

    Erik Petrich - 2004-09-18
    • milestone: --> fixed
    • status: open --> closed-fixed
     
  • Erik Petrich

    Erik Petrich - 2004-09-18

    Logged In: YES
    user_id=635249

    After looking over the C standard's grammer, I realize that
    the first example really is a syntax error. However, I have
    gone ahead and changed sdcc's grammer to parse an assignment
    to a cast object so that it will give a more specific error
    message (lvalue required).

    Updated in src/SDCC.y 1.96

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks