Re: [OT] Re: 2 stupid array questions!!

From: Alan Balmer (albalmer_at_att.net)
Date: 10/10/03


Date: Fri, 10 Oct 2003 14:26:41 -0700

On Fri, 10 Oct 2003 23:23:45 +0200, "Ivan Vecerina"
<ivecATmyrealboxDOTcom> wrote:

>> > // returns the size of the C array passed as a param
>> > // This is safer than the sizeof(a)/sizeof(a[0]) trick...
>> > template <typename T, int N> inline
>> > int arraySize(T (&)[N]) { return N; }
>>
>> This can only be used in the scope of the declaration of the array you're
>> going to pass along.
>
>Yes. And it will produce a compile error when mis-used.
>As stated in my comment, this is much safer than the classic sizeof trick.

It *always* produces a compile-time error in C.

*Please* move this thread to a C++ group.

--
Al Balmer
Balmer Consulting
removebalmerconsultingthis@att.net


Relevant Pages

  • RE: Reinit arrays for non destructive reuse
    ... I've been trying to insert an array ref within a hash. ... test program which was successful, ... is already in scope. ... "my" variable %details masks earlier declaration in same scope at ... ...
    (perl.beginners)
  • Multiple "MY" Same Variable - Release Bytes?
    ... Discussion is of declaring an array variable, ... Note this is different than a variable simply falling out ... of scope within a block. ... The third and final my declaration removes defined status ...
    (comp.lang.perl.misc)
  • Re: arrays of function pointers impossible?
    ... I tried making an array of function pointers returning an int. ... declaration of `f' as array of functions ...
    (comp.lang.c)
  • Re: allocatable array from subroutine
    ...  Then delete the declaration for my_arr from within the subroutine. ... The array my_arr will then have a scope within both the main program and the subroutine. ...
    (comp.lang.fortran)
  • Re: allocatable array from subroutine
    ...  Then delete the declaration for my_arr from within the subroutine. ... The array my_arr will then have a scope within both the main program and the subroutine. ...
    (comp.lang.fortran)