![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 21
Rep Power: 0
![]() |
sizeof question
in line 26
assert(maxIdFun==sizeof FunctionArray/sizeof FunctionArray[0]) what is the size of functionArray and size of functionArray[0] i cant understand that... and how come it would equal to maxIdFun... and the point of dividing it c++ Syntax (Toggle Plain Text)
thanks a lot
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,729
Rep Power: 5
![]() |
Re: sizeof question
The purpose of that statement is to assert that there are actually 14 elements in the array "FunctionArray". It accomplishes this by dividing the total number of bytes in the array (sizeof FunctionArray) by the number of bytes in the first element of the array (sizeof FunctionArray[0]). Since the size of the first element is the same as every other element, the resulting quotient is the number of elements in the array. If this doesn't equal maxIdFun, we have a problem, since maxIdFun is used to determine which elements in the array are accessable.
But beware, this kind of sizeof trick can only be used on arrays where the compiler knows the size of it in advance. |
|
|
|
|
|
#3 |
|
Bug developer
Join Date: Apr 2008
Posts: 6
Rep Power: 0
![]() |
Re: sizeof question
>But beware, this kind of sizeof trick can only be used on
>arrays where the compiler knows the size of it in advance. And of course, don't use it on a pointer. Even if they do seem a lot like arrays... |
|
|
|
|
|
#4 | |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 21
Rep Power: 0
![]() |
Re: sizeof question
Quote:
anyway tnx sane
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,729
Rep Power: 5
![]() |
Re: sizeof question
Yes. You can't "use it on a pointer" because the compiler doesn't know the size of its array in advance. If you need the size of a dynamically allocated array, or a pointer to an array, you need to keep track of the size yourself.
|
|
|
|
|
|
#6 |
|
Unknown
Join Date: Apr 2008
Location: unknown
Posts: 21
Rep Power: 0
![]() |
Re: sizeof question
ok... thnx sane
__________________
------------------------------------------------------------------------- I thought what I'd Do was, I'd pretend to be one of those deaf mutes ------------------------------------------------------------------------ |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Virtual pet site MySQL question | proudnerd | PHP | 6 | May 13th, 2006 7:22 PM |
| C++ template and namespace question | Soulstorm | C++ | 3 | Jan 22nd, 2006 2:46 PM |
| How to post a question | nnxion | C++ | 10 | Jun 3rd, 2005 11:53 AM |
| How to post a question | nnxion | C++ | 0 | Jun 3rd, 2005 8:55 AM |
| How to post a question | nnxion | C | 0 | Jun 3rd, 2005 8:55 AM |