lallous
2010-02-24 12:25:00 UTC
Hello
I have this code:
#include <stdio.h>
#include <stdarg.h>
bool abc1(
unsigned long &v1,
unsigned long &v2,
unsigned long &v3,
...)
{
va_list va;
va_start(va, v3);
printf("<abc1> ");
for (int i=0;i<5;i++)
{
printf("%02x ", va_arg(va, int) & 0xff);
}
printf("</abc1>\n");
va_end(va);
return true;
}
bool abc2(
unsigned long v1,
unsigned long v2,
unsigned long v3,
...)
{
va_list va;
va_start(va, v3);
printf("<abc2> ");
for (int i=0;i<5;i++)
{
printf("%02x ", va_arg(va, int) & 0xff);
}
printf("</abc2>\n");
va_end(va);
return true;
}
int main()
{
unsigned long r1=0, r2=0, r3=0;
abc1(r1, r2, r3,
0x54,0x01,0x00,0x00,0x00,0x58,0x05,0x00,0x00,0x00,0x28,0x02,0x00,0x00,0x00,0x16,0xff,
0xff,0xff,0xff,0xff);
abc2(r1, r2, r3,
0x54,0x01,0x00,0x00,0x00,0x58,0x05,0x00,0x00,0x00,0x28,0x02,0x00,0x00,0x00,0x16,0xff,
0xff,0xff,0xff,0xff);
return 0;
}
The only difference between abc1() and abc2() is that the first three
arguments are passed by value or by reference. Now the output is
different, when compiled:
C:\Temp>cl32 abc.cpp & abc
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01
for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
abc.cpp
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:abc.exe
abc.obj
<abc1> 00 00 88 94 01 </abc1>
<abc2> 54 01 00 00 00 </abc2>
Please advise.
--
Elias
I have this code:
#include <stdio.h>
#include <stdarg.h>
bool abc1(
unsigned long &v1,
unsigned long &v2,
unsigned long &v3,
...)
{
va_list va;
va_start(va, v3);
printf("<abc1> ");
for (int i=0;i<5;i++)
{
printf("%02x ", va_arg(va, int) & 0xff);
}
printf("</abc1>\n");
va_end(va);
return true;
}
bool abc2(
unsigned long v1,
unsigned long v2,
unsigned long v3,
...)
{
va_list va;
va_start(va, v3);
printf("<abc2> ");
for (int i=0;i<5;i++)
{
printf("%02x ", va_arg(va, int) & 0xff);
}
printf("</abc2>\n");
va_end(va);
return true;
}
int main()
{
unsigned long r1=0, r2=0, r3=0;
abc1(r1, r2, r3,
0x54,0x01,0x00,0x00,0x00,0x58,0x05,0x00,0x00,0x00,0x28,0x02,0x00,0x00,0x00,0x16,0xff,
0xff,0xff,0xff,0xff);
abc2(r1, r2, r3,
0x54,0x01,0x00,0x00,0x00,0x58,0x05,0x00,0x00,0x00,0x28,0x02,0x00,0x00,0x00,0x16,0xff,
0xff,0xff,0xff,0xff);
return 0;
}
The only difference between abc1() and abc2() is that the first three
arguments are passed by value or by reference. Now the output is
different, when compiled:
C:\Temp>cl32 abc.cpp & abc
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01
for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
abc.cpp
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:abc.exe
abc.obj
<abc1> 00 00 88 94 01 </abc1>
<abc2> 54 01 00 00 00 </abc2>
Please advise.
--
Elias