Click here to Skip to main content
15,898,035 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionDirectX OverLay ? Pin
seq-5-Sep-05 11:08
seq-5-Sep-05 11:08 
QuestionAddstore() [Outlook Automation] problem Pin
_kane_5-Sep-05 10:25
_kane_5-Sep-05 10:25 
QuestionDEBUG_NEW Pin
Klempie5-Sep-05 8:27
Klempie5-Sep-05 8:27 
AnswerRe: DEBUG_NEW Pin
Bob Stanneveld5-Sep-05 9:41
Bob Stanneveld5-Sep-05 9:41 
Questionhow to get the size of an array Pin
Waleed Eissa5-Sep-05 8:00
Waleed Eissa5-Sep-05 8:00 
AnswerRe: how to get the size of an array Pin
Chris Losinger5-Sep-05 8:07
professionalChris Losinger5-Sep-05 8:07 
GeneralRe: how to get the size of an array Pin
Bob Stanneveld5-Sep-05 9:44
Bob Stanneveld5-Sep-05 9:44 
GeneralRe: how to get the size of an array Pin
Jose Lamas Rios5-Sep-05 16:33
Jose Lamas Rios5-Sep-05 16:33 
That macro only works if the compiler can see X as an array:
#define COUNT_OF(X)  (sizeof(X) / sizeof((X)[0]))
 
void DisplayNumbers(int[6] numbers);
void DisplayNumbers2(int* pNumbers);
void DisplayNumbers3(int* pNumbers, int nSize);
 
void main()
{
   int numbers[] = {1, 2, 3, 5, 8, 13};
 
   // Here it works fine
   int nSize = COUNT_OF(numbers);
 
   DisplayNumbers(numbers);
 
   DisplayNumbers2(numbers);
 
   DisplayNumbers3(numbers, nSize);
}
 
void DisplayNumbers(int[6] numbers)
{
   printf("DisplayNumbers shows:\n   ");
 
   // Here it works fine too, although it's
   // not very useful because you are already
   // stating the size is 6
   int nSize = COUNT_OF(numbers);
   for (int i = 0; i < nSize; ++i)
      printf("%d ", numbers[i]);
 
   printf("\n");
}
 
void DisplayNumbers2(int* pNumbers)
{
   printf("DisplayNumbers2 shows:\n   ");
 
   // Here it doesn't work at all, because for
   // all the compiler knows, pNumbers is just
   // a pointer to an int. Thus, sizeof(X) in
   // the macro will return 4 (i.e., the size
   // of any pointer), sizeof((X)[0]) will
   // return 4 too, and the result for COUNT_OF(X)
   // will then be 1.
   int nSize = COUNT_OF(pNumbers); // will return 1
   for (int i = 0; i < nSize; ++i)
      printf("%d ", numbers[i]);
 
   printf("\n");
}
 
void DisplayNumbers3(int* pNumbers, int nSize)
{
   printf("DisplayNumbers3 shows:\n   ");
 
   for (int i = 0; i < nSize; ++i)
      printf("%d ", numbers[i]);
 
   printf("\n");
}

The output for this program would be:
DisplayNumbers shows:
   1 2 3 5 8 13 
DisplayNumbers2 shows:
   1
DisplayNumbers3 shows:
   1 2 3 5 8 13 


--
jlr
http://jlamas.blogspot.com/[^]
GeneralRe: how to get the size of an array Pin
Jose Lamas Rios5-Sep-05 16:07
Jose Lamas Rios5-Sep-05 16:07 
AnswerRe: how to get the size of an array Pin
toxcct5-Sep-05 21:20
toxcct5-Sep-05 21:20 
AnswerRe: how to get the size of an array Pin
Waleed Eissa6-Sep-05 4:56
Waleed Eissa6-Sep-05 4:56 
QuestionDraw Icon In Combo Box Pin
Skute5-Sep-05 5:58
Skute5-Sep-05 5:58 
QuestionDynamic Disk Pin
sanjaylk5-Sep-05 5:53
sanjaylk5-Sep-05 5:53 
QuestionVC6 compiler bug? Pin
Ravi Bhavnani5-Sep-05 5:24
professionalRavi Bhavnani5-Sep-05 5:24 
AnswerRe: VC6 compiler bug? Pin
Gary R. Wheeler5-Sep-05 5:35
Gary R. Wheeler5-Sep-05 5:35 
GeneralRe: VC6 compiler bug? Pin
Ravi Bhavnani5-Sep-05 5:45
professionalRavi Bhavnani5-Sep-05 5:45 
GeneralRe: VC6 compiler bug? Pin
Gary R. Wheeler5-Sep-05 5:49
Gary R. Wheeler5-Sep-05 5:49 
GeneralRe: VC6 compiler bug? Pin
Bob Stanneveld5-Sep-05 9:46
Bob Stanneveld5-Sep-05 9:46 
GeneralRe: VC6 compiler bug? Pin
Ravi Bhavnani5-Sep-05 9:53
professionalRavi Bhavnani5-Sep-05 9:53 
QuestionHelp on WebBrowser Pin
Cao Jianlin5-Sep-05 5:05
Cao Jianlin5-Sep-05 5:05 
QuestionRegistry Editing C++ Pin
u6ik5-Sep-05 5:03
u6ik5-Sep-05 5:03 
AnswerRe: Registry Editing C++ Pin
u6ik5-Sep-05 6:44
u6ik5-Sep-05 6:44 
QuestionAbout MS Access Database in vc++:==Plz Help Pin
parims5-Sep-05 3:13
parims5-Sep-05 3:13 
AnswerRe: About MS Access Database in vc++:==Plz Help Pin
Marc Soleda5-Sep-05 3:39
Marc Soleda5-Sep-05 3:39 
QuestionRemove Device Pin
Peter Prescher5-Sep-05 2:56
Peter Prescher5-Sep-05 2:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.