On 16/03/15 14:07, Ben Bacarisse wrote:
> Martin Guy <[email protected]> writes:
> <snip>
>> The reason is to work round what looks like a bug in the 64-bit
>> pointer handling, which is
>> fairly easy to workaround:
>>
>> /* Tickle a bug in TinyC on 64-bit systems:
>>  * the LSB of the top word or ARGP gets set
>>  * for no obvious reason.
>>  *
>>  * Source: a legacy language interpreter which
>>  * has a little stack / stack pointer for arguments.
>>  *
>>  * Output is: 0x8049620 0x10804961c
>>  * Should be: 0x8049620 0x804961c
>>  */
>>
>> #define NARGS 20000
>> int ARG[NARGS];
>> int *ARGSPACE = ARG;
>> int *ARGP = ARG - 1;
> 
> As it happens, this is undefined behaviour by the C language standard --
> you can't even construct (let alone use) a pointer that points "before"
> the start of an array.  I don't know whether TinyC is using the
> permission this gives the implementation, but it is technically free to
> do whatever it likes in this situation.

Yep, I was about to say exactly the same[1], and suggest the following:

#define NARGS 20000
int ARGV[NARGS+1];
int *ARG = ARGV + 1;
int *ARGSPACE = ARG;
int *ARGP = ARG - 1;

... or something like that. (warning: just typing into email client.)

ATB,
Ramsay Jones

[1] In a draft of the C11 standard I have, this is discussed in
'6.5.6 Additive Operators'.




_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to