Question about definitions

T

Thomas Barth

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.
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Thomas said:
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.
 
J

John Harrison

Thomas Barth said:
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
 
V

Victor Bazarov

Thomas said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top