[Top][All Lists]

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

Re: [Tinycc-devel] C99 static array indices in function args

From: Michael B. Smith
Subject: Re: [Tinycc-devel] C99 static array indices in function args
Date: Wed, 20 Dec 2017 00:51:51 +0000

It's in in C99 for 'static'.

It's in 6.7.3/5 in C99 for 'const'.

Using 'static' seems to have two implied contracts:

[1] don't allow NULL parameters
[2] verify, when possible, that the passed array has AT LEAST the number of 
elements defined

Using 'const' has an implied contract:

[3] treat the array as if were a const array (e.g., "char a[const] --> char * 
const a")

Recent versions of gcc and clang do 1 and 2 (as warnings). I can't find 
anything definitive about 3.

'restrict' is allowed by tcc, but ignored. I think that that is a bug. 
'restrict' has several defined (not just implied) contracts. This should 
require at least a warning.

Supporting 'const' properly is actually pretty easy.

Supporting 'static' - well, [1] requires that tcc generate code (to handle both 
runtime and compile-time cases), and [2] may (or may not) be easy to do 
depending on the parameter. If we assume locally defined arrays, like VLAs, 
then it is easy.

However, supporting 'static' does not require diagnostics (unlike 'const'). 
They can be ignored and the behavior is simply 'undefined'. Not that I think 
that is proper. I would think to emit warnings that I was ignoring the intended 
impact of the modifier.

In tcc, see tccgen.c beginning at 4,334 and at 3,998 for parse_btype.

-----Original Message-----
From: Tinycc-devel [mailto:address@hidden On Behalf Of foobar
Sent: Tuesday, December 19, 2017 5:11 PM
To: address@hidden
Subject: [Tinycc-devel] C99 static array indices in function args

tcc chokes on encountering a function definition like

void foo(char bar[static 16]) { ... }


are there plans to support this feature ?

i think basically tcc could just ignore the static or const keyword there and 
treat it as if the declaration was:

void foo(char bar[16]) { ... }

(the feature is described in the C11 specs in §, § part 7, but 
IIRC it's also in C99)

Tinycc-devel mailing list

reply via email to

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