Quel est l'intêret de déclarer un tableau de cette manière:
struct a {
struct tc_u32_key keys[0];
...
}
plutot que:
struct a {
struct tc_u32_key *keys;
...
}
J'ai vu pas mal de fois ca dans du code, et lors de la libération de
mémoire, le free est effectué sur la structure a et non explicitement
auparavant sur les éléménts du tableau de la sous-structure.
In 'fr.comp.lang.c', Vincent Lefevre <vincent+ wrote:
struct a { struct tc_u32_key keys[0];
On ne peut pas faire ça en C standard C90, mais c'est permis en C99.
Ah bon? Citation?
6.7.5.2 Array declarators Constraints 1 The [ and ] may delimit an expression or *. If [ and ] delimit an expression (which specifies the size of an array), it shall have an integer type. If the expression is a constant expression then it shall have a value greater than zero. The element type shall not be an incomplete or function type.
Effectivement, dans N869 (C9x), c'est pas permis. Peut être un changement de dernière minute dans C99?
Il m'a semblé lire ça sur clc, comme étant un 'entérinement' de la pratique du tab[1] en fin de structure...
En fait il s'agit du 'flexible array', et la syntaxe est tab[].
-- -ed- [remove YOURBRA before answering me] The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html <blank line> FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
In 'fr.comp.lang.c', Emmanuel Delahaye <emdelYOURBRA@noos.fr> wrote:
In 'fr.comp.lang.c', Vincent Lefevre <vincent+news@vinc17.org> wrote:
struct a {
struct tc_u32_key keys[0];
On ne peut pas faire ça en C standard C90, mais c'est permis en C99.
Ah bon? Citation?
6.7.5.2 Array declarators
Constraints
1 The [ and ] may delimit an expression or *. If [ and ] delimit an
expression (which specifies the size of an array), it shall have an
integer type. If the expression is a constant expression then it shall
have a value greater than zero. The element type shall not be an
incomplete or function type.
Effectivement, dans N869 (C9x), c'est pas permis. Peut être un
changement de dernière minute dans C99?
Il m'a semblé lire ça sur clc, comme étant un 'entérinement' de la
pratique du tab[1] en fin de structure...
En fait il s'agit du 'flexible array', et la syntaxe est tab[].
--
-ed- emdelYOURBRA@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
In 'fr.comp.lang.c', Vincent Lefevre <vincent+ wrote:
struct a { struct tc_u32_key keys[0];
On ne peut pas faire ça en C standard C90, mais c'est permis en C99.
Ah bon? Citation?
6.7.5.2 Array declarators Constraints 1 The [ and ] may delimit an expression or *. If [ and ] delimit an expression (which specifies the size of an array), it shall have an integer type. If the expression is a constant expression then it shall have a value greater than zero. The element type shall not be an incomplete or function type.
Effectivement, dans N869 (C9x), c'est pas permis. Peut être un changement de dernière minute dans C99?
Il m'a semblé lire ça sur clc, comme étant un 'entérinement' de la pratique du tab[1] en fin de structure...
En fait il s'agit du 'flexible array', et la syntaxe est tab[].
-- -ed- [remove YOURBRA before answering me] The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html <blank line> FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Gabriel Dos Reis
Emmanuel Delahaye writes:
| Effectivement, dans N869 (C9x), c'est pas permis. Peut être un changement de | dernière minute dans C99?
Non.
Constraints
[#1] In addition to optional type qualifiers and the keyword static, the [ and ] may delimit an expression or *. If they delimit an expression (which specifies the size of an array), the expression shall have an integer type. If the expression is a constant expression, it shall have a value greater than zero. The element type shall not be an incomplete or function type. The optional type qualifiers and the keyword static shall appear only in a declaration of a function parameter with an array type, and then only in the outermost array type derivation.
-- Gaby
Emmanuel Delahaye <emdelYOURBRA@noos.fr> writes:
| Effectivement, dans N869 (C9x), c'est pas permis. Peut être un changement de
| dernière minute dans C99?
Non.
Constraints
[#1] In addition to optional type qualifiers and the keyword
static, the [ and ] may delimit an expression or *. If they
delimit an expression (which specifies the size of an
array), the expression shall have an integer type. If the
expression is a constant expression, it shall have a value
greater than zero. The element type shall not be an
incomplete or function type. The optional type qualifiers
and the keyword static shall appear only in a declaration of
a function parameter with an array type, and then only in
the outermost array type derivation.
| Effectivement, dans N869 (C9x), c'est pas permis. Peut être un changement de | dernière minute dans C99?
Non.
Constraints
[#1] In addition to optional type qualifiers and the keyword static, the [ and ] may delimit an expression or *. If they delimit an expression (which specifies the size of an array), the expression shall have an integer type. If the expression is a constant expression, it shall have a value greater than zero. The element type shall not be an incomplete or function type. The optional type qualifiers and the keyword static shall appear only in a declaration of a function parameter with an array type, and then only in the outermost array type derivation.
-- Gaby
Gabriel Dos Reis
Francois Cartegnie writes:
| Gabriel Dos Reis wrote: | > Vincent Lefevre <vincent+ writes: | > | Dans l'article <bgt5jm$jev$, | > | Francois Cartegnie écrit: | > | | > Quel est l'intêret de déclarer un tableau de cette manière: | > | | > struct a { | > | > struct tc_u32_key keys[0]; | > | > ... | > | > } | > | | J'ai l'impression que ce n'est pas correct: | > Yep. Par contre, GNU C autorise cette extension -- je ne sais pas si | > GNU C l'a piquée quelque part ou si c'est son invention. | | Ca vient du noyau linux, donc GNU compilé avec un compilateur GNU | (gcc)... Donc c'est pas forcément portable ailleurs.
Le point de ma remarque est qu'il y a des extensions GNU qui sont en fait piquées d'ailleurs. Ce n'est parce que c'est GNU que forcément ce n'est pas protable ailleurs.
-- Gaby
Francois Cartegnie <NOSPAM@TAMAMAN.OWC> writes:
| Gabriel Dos Reis wrote:
| > Vincent Lefevre <vincent+news@vinc17.org> writes:
| > | Dans l'article <bgt5jm$jev$1@aphrodite.grec.isp.9tel.net>,
| > | Francois Cartegnie <NOSPAM@tamaman.owc> écrit:
| > | | > Quel est l'intêret de déclarer un tableau de cette manière:
| > | | > struct a {
| > | > struct tc_u32_key keys[0];
| > | > ...
| > | > }
| > | | J'ai l'impression que ce n'est pas correct:
| > Yep. Par contre, GNU C autorise cette extension -- je ne sais pas si
| > GNU C l'a piquée quelque part ou si c'est son invention.
|
| Ca vient du noyau linux, donc GNU compilé avec un compilateur GNU
| (gcc)... Donc c'est pas forcément portable ailleurs.
Le point de ma remarque est qu'il y a des extensions GNU qui sont en
fait piquées d'ailleurs. Ce n'est parce que c'est GNU que forcément
ce n'est pas protable ailleurs.
| Gabriel Dos Reis wrote: | > Vincent Lefevre <vincent+ writes: | > | Dans l'article <bgt5jm$jev$, | > | Francois Cartegnie écrit: | > | | > Quel est l'intêret de déclarer un tableau de cette manière: | > | | > struct a { | > | > struct tc_u32_key keys[0]; | > | > ... | > | > } | > | | J'ai l'impression que ce n'est pas correct: | > Yep. Par contre, GNU C autorise cette extension -- je ne sais pas si | > GNU C l'a piquée quelque part ou si c'est son invention. | | Ca vient du noyau linux, donc GNU compilé avec un compilateur GNU | (gcc)... Donc c'est pas forcément portable ailleurs.
Le point de ma remarque est qu'il y a des extensions GNU qui sont en fait piquées d'ailleurs. Ce n'est parce que c'est GNU que forcément ce n'est pas protable ailleurs.