From: Johan Knol <johan.knol@id...> - 2001-09-26 16:57:06
For this, I again disabled Sandeep's fix in SDCCast.c:1.75&1.77. I moved the
test from decorateType() to geniCodeCast(). Now it will also test implicit
casts, as with "char *a='b'. It doesn't change or "assume" anything anymore
when doing freaky things with a gpointer. Doing this is an error now.
Sandeep, do we agree?
> Code A:
> char a=0;
> char* p=a;
> This is accepted without error. But I suspect there should be
> an error or a warning here.
Fixed in SDCCast.c:decorateType()/geniCodeCast()
> Code B:
> int* a=0;
> char* p=a;
> This is also accepted without error. But if I interpret the C standard
> correctly this is not valid without a cast. Probably a warning but
> again I'm not sure.
An initializer needs to be a constant, so this is not allowed anyway. SDCC
still allows this (just because it can) but doesn't check the etypes
correctly, as mentioned before. This is a know "feature".
> Code C:
> void (*a)(void) = 0;
> char* p = a;
> This is also accepted, see B, but might be an error instead.
Now an error is thrown.
> Code D:
> char* a=0xA000;
> char* p=(char*)0xA000;
> The first line is ok, but the second generates:
> warning *** illegal cast of LITERAL value to 'generic' pointer: assuming
> Which is probably an incorrect warning because the z80 does not have
> an xdata segment (does it?) and also strange because the first line is
> accepted without error.
Both throw an error now. No more "assumes", you should fix this first.
> And as I went on experimenting:
> Code E:
> char const *p = 0;
> Is accepted, but shouldn't.
It isn't anymore.
> Anyway, I know all of these are bad code but it could have saved me
> a few minutes of debugging if the compiler had generated a message.
> Keep up the good work!
Yap, but we need guys like you to keep us going ...
This again reveals new bug's in the library (type cast required in
malloc.c:84, illegal const writes in vprintf.c():294). All of them are now
correct errors as far as I can see. Could someone take care of that?
Ofcourse I overlooked something again, please point me to it.
From: Johan Knol <johan.knol@id...> - 2001-09-27 09:26:38
> This again reveals new bug's in the library (type cast required in
> malloc.c:84, illegal const writes in vprintf.c():294). All of them are now
> correct errors as far as I can see. Could someone take care of that?
Never mind, fixed already. Will commit it within an hour or so.
> Ofcourse I overlooked something again, please point me to it.
From: Johan Knol <johan.knol@id...> - 2001-09-27 11:06:22
> > And as I went on experimenting:
> > Code E:
> > char const *p = 0;
> > ++p;
> > Is accepted, but shouldn't.
> It isn't anymore.
I was fooled by this one, this is perfectly legal. You can't to ++(*p). If
you had "char * const p=0" you can't do ++p.