| ??? 01/13/11 08:59 Read: times |
#180546 - 0 is special - but so is NULL. indexing around NULL is bad Responding to: ???'s previous message |
Jan Waclawek said:
This is a bit strange, as ((char *)1)[0x10] = 0; warns about "cast of LITERAL value to 'generic' pointer". I'd say this would be appropriate for the null constant cast to non-(void *) (i.e. creating null pointer) too. Casting of 0 is always special in the language, since 0 is a synonym for NULL. In the sibling language C++, the recommendation is to use 0 instead of NULL in the source code. But in both languaes, the compiler is required to see a 0 as a NULL pointer even if the hardware would happen to use something else to represent NULL internally. Anyway - I do not like indexing around a NULL pointer. A NULL pointer (which 0 is) may point to the start of memory range (which it does in most architectures, even if that address range may be empty and create read and/or write exceptions). But the standard doesn't guarantee that a NULL pointer points to any memory range at all. The architecture may have a hidden bit in all address registers to represent the address as valid or a NULL. Such a architecture would obviously not manage a type cast from a NULL pointer to another data type and then the addition of an offset. The magical "NULL" or "invalid" bit would still be set and any offset would still represent a NULL. |
| Topic | Author | Date |
| sdcc internal error / C syntax | 01/01/70 00:00 | |
| legality of indexing NULL pointer | 01/01/70 00:00 | |
| bug | 01/01/70 00:00 | |
| version | 01/01/70 00:00 | |
| version revisited | 01/01/70 00:00 | |
| thank you | 01/01/70 00:00 | |
| Fixed | 01/01/70 00:00 | |
| no snapshot | 01/01/70 00:00 | |
| works | 01/01/70 00:00 | |
| 0 is special - but so is NULL. indexing around NULL is bad | 01/01/70 00:00 | |
| No guarantee that a NULL pointer points to any memory | 01/01/70 00:00 | |
| time | 01/01/70 00:00 | |
| I know :-( | 01/01/70 00:00 | |
| Use of __at ? | 01/01/70 00:00 | |
| What is "that way"? | 01/01/70 00:00 | |
| the antique version.... | 01/01/70 00:00 | |
| XBYTE macro | 01/01/70 00:00 | |
| Okay, then the following definition... | 01/01/70 00:00 | |
| RE: David's remarks about volatility | 01/01/70 00:00 | |
| Close, but no cigar | 01/01/70 00:00 | |
| Avoid the 'volatile' | 01/01/70 00:00 | |
| instead of offsetting... | 01/01/70 00:00 | |
| Dereferencing a '_REG | 01/01/70 00:00 | |
I agree | 01/01/70 00:00 | |
| Use of __at ? [ed] | 01/01/70 00:00 |



