Question about definitions

Discussion in 'C++' started by Thomas Barth, Nov 15, 2004.

  1. Thomas Barth

    Thomas Barth Guest

    Hi,
    I don't understand the following definitions in a
    header-file for sample codes, that have been written in msvs.
    I try to get the sample codes "clean" to compiling them
    with the GNU-Compiler.

    #ifdef _X86_
    #define DebugBreak() _asm { int 3 }
    #endif


    When using DebugBreak, the GNU-Compiler prints the error:

    inline void chFAIL(PSTR szMsg) {
    chMB(szMsg);
    DebugBreak(); //error*

    }

    *error: multiple markers at this line
    - _asm undeclared (first use this function)
    - parse error before '{' token


    I am also confused of "_asm { int 3 } " I can't find an
    explanation for that in my C++ books.


    #define chBEGINTHREADEX(psa, cbStack, pfnStartAddr, \
    pvParam, fdwCreate, pdwThreadId) \
    ((HANDLE)_beginthreadex( \
    (void *) (psa), \
    (unsigned) (cbStack), \
    (PTHREAD_START) (pfnStartAddr), \
    (void *) (pvParam), \
    (unsigned) (fdwCreate), \
    (unsigned *) (pdwThreadId)))


    An inline function is the better choice, isn't it?

    Thanks in advance,
    Thomas B.
    Thomas Barth, Nov 15, 2004
    #1
    1. Advertising

  2. Thomas Barth wrote:
    > Hi,
    > I don't understand the following definitions in a
    > header-file for sample codes, that have been written in msvs.
    > I try to get the sample codes "clean" to compiling them
    > with the GNU-Compiler.
    >
    > #ifdef _X86_
    > #define DebugBreak() _asm { int 3 }
    > #endif
    >
    >
    > When using DebugBreak, the GNU-Compiler prints the error:
    >
    > inline void chFAIL(PSTR szMsg) {
    > chMB(szMsg);
    > DebugBreak(); //error*
    >
    > }
    >
    > *error: multiple markers at this line
    > - _asm undeclared (first use this function)
    > - parse error before '{' token


    inline assembly is non standard and usually highly compiler
    dependant.
    Read up on inline asm in the gcc docs, the above seems to be written
    for another compiler.

    --
    Nils O. SelÄsdal
    www.utelsystems.com
    =?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=, Nov 15, 2004
    #2
    1. Advertising

  3. "Thomas Barth" <> wrote in message
    news:...
    > Hi,
    > I don't understand the following definitions in a
    > header-file for sample codes, that have been written in msvs.
    > I try to get the sample codes "clean" to compiling them
    > with the GNU-Compiler.
    >
    > #ifdef _X86_
    > #define DebugBreak() _asm { int 3 }
    > #endif
    >
    >
    > When using DebugBreak, the GNU-Compiler prints the error:
    >
    > inline void chFAIL(PSTR szMsg) {
    > chMB(szMsg);
    > DebugBreak(); //error*
    >
    > }
    >
    > *error: multiple markers at this line
    > - _asm undeclared (first use this function)
    > - parse error before '{' token
    >
    >
    > I am also confused of "_asm { int 3 } " I can't find an
    > explanation for that in my C++ books.


    _asm is non-standard, that is why you can't find it in your C++ books and
    why the g++ compiler won't compile it. You will have to check with an MS
    group but I think that DebugBreak is a way of activating the debugger for
    your system. I have no idea what the equivalent for g++ would be.

    >
    >
    > #define chBEGINTHREADEX(psa, cbStack, pfnStartAddr, \
    > pvParam, fdwCreate, pdwThreadId) \
    > ((HANDLE)_beginthreadex( \
    > (void *) (psa), \
    > (unsigned) (cbStack), \
    > (PTHREAD_START) (pfnStartAddr), \
    > (void *) (pvParam), \
    > (unsigned) (fdwCreate), \
    > (unsigned *) (pdwThreadId)))
    >
    >
    > An inline function is the better choice, isn't it?


    Yes.

    John
    John Harrison, Nov 15, 2004
    #3
  4. Thomas Barth wrote:
    > I don't understand the following definitions in a
    > header-file for sample codes, that have been written in msvs.
    > I try to get the sample codes "clean" to compiling them
    > with the GNU-Compiler.
    >
    > #ifdef _X86_
    > #define DebugBreak() _asm { int 3 }
    > #endif
    >
    >
    > When using DebugBreak, the GNU-Compiler prints the error:
    >
    > inline void chFAIL(PSTR szMsg) {
    > chMB(szMsg);
    > DebugBreak(); //error*
    >
    > }
    >
    > *error: multiple markers at this line
    > - _asm undeclared (first use this function)
    > - parse error before '{' token


    Well, you could try replacing '_asm' with 'asm' to get it to work,
    but beware that interrupt 3 is not necessarily supported in your GNU
    debugger as a 'software breakpoint'.

    _asm is Microsoft-specific. Using 'int 3' as a "software breakpoint"
    is also Microsoft-specific. I recommend you change the macro to be

    #ifdef _X86_
    # ifdef _MSC_VER
    # define DebugBreak() _asm { int 3 }
    # else
    # define DebugBreak() 0
    # endif
    #endif

    >
    >
    > I am also confused of "_asm { int 3 } " I can't find an
    > explanation for that in my C++ books.


    You're reading wrong books :). You need Microsoft-specific ones.

    > #define chBEGINTHREADEX(psa, cbStack, pfnStartAddr, \
    > pvParam, fdwCreate, pdwThreadId) \
    > ((HANDLE)_beginthreadex( \
    > (void *) (psa), \
    > (unsigned) (cbStack), \
    > (PTHREAD_START) (pfnStartAddr), \
    > (void *) (pvParam), \
    > (unsigned) (fdwCreate), \
    > (unsigned *) (pdwThreadId)))
    >
    >
    > An inline function is the better choice, isn't it?


    Better choice for what?

    V
    Victor Bazarov, Nov 15, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ark

    A question on incomplete definitions

    ark, Dec 17, 2003, in forum: C Programming
    Replies:
    24
    Views:
    855
    Peter Shaggy Haywood
    Dec 22, 2003
  2. ishtar2020
    Replies:
    2
    Views:
    980
    Simon Forman
    Aug 28, 2006
  3. Roman Mashak

    question about 'static' definitions

    Roman Mashak, May 21, 2005, in forum: C Programming
    Replies:
    3
    Views:
    313
    Malcolm
    May 21, 2005
  4. raphfrk

    question on variable definitions

    raphfrk, Mar 2, 2007, in forum: C Programming
    Replies:
    23
    Views:
    684
    Bill Pursell
    Mar 3, 2007
  5. Replies:
    17
    Views:
    554
    Michael Fesser
    Feb 8, 2008
Loading...

Share This Page