<<< Date Index >>>     <<< Thread Index >>>

Re: Little code cleanup



On 2008-03-05 14:08:51 +0100, Sébastien Hinderer wrote:
> In the context of an off-list discussion, a friend of mine wrote what
> follows (Actually this was written in french and I am translating):
> 
> In my opinion, the problem comes from the fact that C does not make a
> clear distinction between arrays and pointers which are, however, two
> objects of very different natures. Here fname and mbox are arrays, not
> pointers.

They are arrays, but in expressions, they evaluate to pointers
(with a few exceptions). More precisely:

[ISO C99, 6.3.2.1]
       [#3] Except when it is the operand of the sizeof operator or
       the  unary  &  operator,  or  is  a  string  literal used to
       initialize an array, an expression that has type ``array  of
       type''  is converted to an expression with type ``pointer to
       type'' that points to  the  initial  element  of  the  array
       object  and  is  not  an  lvalue.   If  the array object has
       register storage class, the behavior is undefined.

> This is precisely why one can write things like "sizeof(mbox)".
> Since the abovementionned variables are arrays, it makes not really
> sense to verify that their addresses are non-NULL.

According to the C standard (see above), it makes really sense,
though the value of the resulting pointer (i.e. after the conversion)
is always non-null.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)