Question about definitions 
July 22nd, 2005, 10:54 PM
| | | |
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. | 
July 22nd, 2005, 10:54 PM
| | | | 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 | 
July 22nd, 2005, 10:54 PM
| | | | 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 | 
July 22nd, 2005, 10:54 PM
| | | | 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 |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|