Menu

#1623 Compilation Error on using const variable

closed-fixed
5
2013-05-25
2010-02-22
BLRCalvin
No

Dear developers,

I tested the following example with v2.9 release and with snapshot #5703. In both the cases, it is resulting in a compilation error, which I feel is wrong. Please correct me if I am wrong.

Test.c

#include<stdio.h>

x(const char*s)
{
char a[1];
const char*ss=s;
a[*(s++)]|=1; -----------------------> The value of the constant variable 's' is not modified rather the pointer is incremented for which SDCC is throwing error.
return(int)ss+1==(int)s;
}

main(){
if(x("")!=1)
{
printf("Test Failed");
return -1;
}
else
printf("Test Completed\n");
return 0;
}

command:

sdcc -mmcs51 --model-small Test.c -o Test.hex

Error:

error 33: Attempt to assign value to a constant variable (=)

SDCC 2.9.7 #5703:
SDCC : mcs51/gbz80/z80/ds390/pic16/pic14/TININative/ds400/hc08 2.9.7 #5703 (Feb 21 2010) (MINGW32)

SDCC 2.9:
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.0 #5416 (Mar 22 2009) (MINGW32)

Thanks,
Raghu.

Discussion

  • Maarten Brock

    Maarten Brock - 2010-05-06

    Fixed in SDCC 2.9.7 #5821.

     
  • Maarten Brock

    Maarten Brock - 2010-05-06
    • labels: --> C-Front End
    • milestone: --> fixed
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-fixed
     

Log in to post a comment.