Environment:
gcc-2.95.2-3
Windows 2000
In the following case, __stdcall for TIMECALLBACK1
is ignored.
callback.cpp -------------------------------------
typedef void (__stdcall TIMECALLBACK1)(int,int);
typedef void __stdcall (TIMECALLBACK2)(int,int);
void callFoo(TIMECALLBACK1* callback1, TIMECALLBACK2*
callback2) {
int i;
for (i = 0; i < 1000; i++) {
(*callback1)(1, 2);
}
for (i = 0; i < 1000; i++) {
(*callback2)(1, 2);
}
}
--------------------------------------------------
With "g++ -O2 -S callback.cpp" I got the following:
------------------------------------------
L6:
addl $-8,%esp
pushl $2
pushl $1
call *%esi
addl $16,%esp ;****** <- Problem
decl %ebx
jns L6
movl $999,%ebx
.p2align 4,,7
L11:
addl $-8,%esp
pushl $2
pushl $1
call *%edi
addl $8,%esp ;******
decl %ebx
jns L11
leal -24(%ebp),%esp
-------------------------------------------
Calls for `callback1' is not compiled as __stdcall.
It must be the same as calls for `callback2'.
Workarounds are:
- Use C. This problem occurs only in C++.
- Move the position of __stdcall like TIMECALLBACK2.
But w32api has many typedefs like TIMECALLBACK1.
Logged In: YES
user_id=11494
This bug is fixed by the following patch:
C++ parser bug with function attributes:
http://gcc.gnu.org/ml/gcc-patches/2001-01/msg01751.html
The patch is incorporated in cygwin gcc-2.95.3-2 source
distro.
Danny
Logged In: YES
user_id=163353
That patch did not fix this problem.
Logged In: YES
user_id=163353
gcc-2.95.3-4 in mingw-1.0-20010608 reproduces this problem.
Logged In: YES
user_id=11494
Bad news: with 3.0.2 (prerelease) the bug is still there.
Good news: with trunk CVS it is fixed. This uses a table-
driven approach to attributes.
g++ -S callback.cpp
L5:
subl $8, %esp
pushl $2
pushl $1
movl 8(%ebp), %eax
call *%eax
addl $8, %esp <<<<<<
leal -4(%ebp), %eax
incl (%eax)
jmp L2
<snip>
L9:
subl $8, %esp
pushl $2
pushl $1
movl 12(%ebp), %eax
call *%eax
addl $8, %esp <<<<<<
leal -4(%ebp), %eax
incl (%eax)
jmp L6
L1:
Logged In: YES
user_id=30442
Yes, this is fixed in GCC 3.1.