Connecting Tech Pros Worldwide Help | Site Map

Question about definitions

  #1  
Old July 22nd, 2005, 10:54 PM
Thomas Barth
Guest
 
Posts: n/a
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.


  #2  
Old July 22nd, 2005, 10:54 PM
Nils O. Selåsdal
Guest
 
Posts: n/a

re: Question about definitions


Thomas Barth wrote:[color=blue]
> 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[/color]

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
  #3  
Old July 22nd, 2005, 10:54 PM
John Harrison
Guest
 
Posts: n/a

re: Question about definitions



"Thomas Barth" <th.barth@mail.isis.de> wrote in message
news:2vs1ekF2nk39hU1@uni-berlin.de...[color=blue]
> 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.[/color]

_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.
[color=blue]
>
>
> #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?[/color]

Yes.

John



  #4  
Old July 22nd, 2005, 10:54 PM
Victor Bazarov
Guest
 
Posts: n/a

re: Question about definitions


Thomas Barth wrote:[color=blue]
> 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[/color]

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
[color=blue]
>
>
> I am also confused of "_asm { int 3 } " I can't find an
> explanation for that in my C++ books.[/color]

You're reading wrong books :-). You need Microsoft-specific ones.
[color=blue]
> #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?[/color]

Better choice for what?

V
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
(Silly?) question about linkage of C applications Bit byte answers 12 July 8th, 2006 01:05 PM
question about scope John Salerno answers 10 February 22nd, 2006 10:15 AM
A question about design of using virtual or not Tony Johansson answers 2 August 17th, 2005 01:05 AM
A question about inline Tony Johansson answers 4 July 23rd, 2005 03:54 AM