Re: [cc65] BSS Segment

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2003-08-27 12:15:26


On Wed, Aug 27, 2003 at 07:20:38AM +0200, Groepaz wrote:
> mmmmh i see another funny problem here...what if i really want to assign 0
> (and _not_ NULL, whatever bitpattern it is) because i want to use the pointer
> to access the memory at location 0?

Assigning integer values to pointers is implementation defined (and
dereferencing such pointers may not work at all), so your compiler writer has
to specify in which way this will work.

> int i;
> char *p;
>
>  	i=0;
>  	p=(char*)i;
>
> comes to mind, but would that even work as intended? (the compiler might
> optimize out the helper variable, and then again convert the zero to NULL
> when assigning to the pointer)

No. Only the literal "0" is a NULL pointer constant, not any integer value
that happens to be zero. So the compiler might optimize out the helper
variable, but the result must still be a conversion of an integer with the
value zero to a pointer.

> OR is it so that *(char*)NULL is defined to access memory at location zero?

No. You are not allowed by the standard to dereference a NULL pointer.

See the links I've already posted for more information.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-08-27 12:15:34 CEST