tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Predefined macro identifying TinyC?


From: Ramsay Jones
Subject: Re: [Tinycc-devel] Predefined macro identifying TinyC?
Date: Mon, 16 Mar 2015 15:19:58 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

On 16/03/15 14:07, Ben Bacarisse wrote:
> Martin Guy <address@hidden> 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'.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]