Re: A Certain Size/sizeof
From: Ulrich Eckhardt (doomster_at_knuut.de)
Date: 11/14/03
- Next message: Bill: "Looking for Pulse Position Modulation (PPM) source code"
- Previous message: forums_mp: "Re: std::map -> string, function pointer."
- In reply to: Gene Wirchenko: "A Certain Size/sizeof"
- Next in thread: Gene Wirchenko: "Re: A Certain Size/sizeof"
- Reply: Gene Wirchenko: "Re: A Certain Size/sizeof"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 14 Nov 2003 21:54:34 +0100
Gene Wirchenko wrote:
> int BufferTestNumbers[][17]=
> { ... };
>
> std::string
> TestBuffer[sizeof(BufferTestNumbers)/sizeof(int)/17];
>
> Truly an ugly array size expression, no?
Firstly, sizeof is not a function, therefore 'sizeof BufferTestNumbers'
doesn't need brackets. 'sizeof (int)' is an example the second version to
invoke that operator and that takes a typename in brackets, but still not
a function.
> Is there a way to declare TestBuffer without the magic number? I
> would prefer to keep the declaration of BufferTestNumbers as it is (or
> with very minor changes) as it is easy to adjust should I want other
> test cases. I ask for both C and C++.
assuming I had
int array[] = { 1,2,3,4,5,8,12 };
I usually do
size_t const count = sizeof array / sizeof *array;
Adapting that to a more-dimensional array is left as exercise for
the reader.
Uli
-- Questions ? see C++-FAQ Lite: http://parashift.com/c++-faq-lite/ first !
- Next message: Bill: "Looking for Pulse Position Modulation (PPM) source code"
- Previous message: forums_mp: "Re: std::map -> string, function pointer."
- In reply to: Gene Wirchenko: "A Certain Size/sizeof"
- Next in thread: Gene Wirchenko: "Re: A Certain Size/sizeof"
- Reply: Gene Wirchenko: "Re: A Certain Size/sizeof"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|