Menu

#34 __stdcall and typedef

closed-fixed
nobody
gcc (462)
2002-05-26
2001-04-09
TAMURA Kent
No

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.

Discussion

  • Danny Smith

    Danny Smith - 2001-04-09

    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

     
  • TAMURA Kent

    TAMURA Kent - 2001-04-13

    Logged In: YES
    user_id=163353

    That patch did not fix this problem.

     
  • Earnie Boyd

    Earnie Boyd - 2001-06-20
    • status: open --> closed-fixed
     
  • TAMURA Kent

    TAMURA Kent - 2001-06-21
    • status: closed-fixed --> open-fixed
     
  • TAMURA Kent

    TAMURA Kent - 2001-06-21

    Logged In: YES
    user_id=163353

    gcc-2.95.3-4 in mingw-1.0-20010608 reproduces this problem.

     
  • Danny Smith

    Danny Smith - 2001-10-12

    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:

     
  • Luke Dunstan

    Luke Dunstan - 2002-05-22

    Logged In: YES
    user_id=30442

    Yes, this is fixed in GCC 3.1.

     
  • Danny Smith

    Danny Smith - 2002-05-26
    • status: open-fixed --> closed-fixed