Re: Virtual Machine implementation problem, Please help me to spot the bug
- From: Old Wolf <oldwolf@xxxxxxxxxxxxxx>
- Date: 7 May 2007 16:37:16 -0700
But when I use
to run a UM program, I kept on getting error messages.
What error messages?
#define dprintf(x,...) printf(x,...)
This is non-standard (Conceivably your compiler allows it
as an extension; for the rest of my reply I'll assume
it doesn't).
If your compiler is compliant with C99 you can write:
#define dprintf(x, ...) printf(x, __VA_ARGS__)
after also including <stdarg.h> of course. If your compiler
does not support this then you will have to do something
else, such as:
#define dprintf printf
which would work in this case.
void change_endian(u32* value){
u8 tmp1[4], tmp2[4];
memcpy((u32 *)tmp1, value, sizeof(u32));
tmp1 might not be correctly aligned for u32.
tmp2[0] = tmp1[3];
tmp2[1] = tmp1[2];
tmp2[2] = tmp1[1];
tmp2[3] = tmp1[0];
memcpy(value, (u32 *)tmp2, sizeof(u32));
}
Code like this is likely to cause problems. You should re-write
the code to:
* Not depend on any endian issues
* Not use any casts
* Not rely on alignment
Of course there are one or two rare situations when casts
are necessary, but almost every one in your code is
masking potential undefined behaviour.
The above function could be improved to: (note, better
would be to write code that doesn't use it at all, and
the following would still cause trouble on the DS9000)
void change_endian(u32* value){
u8 *ptr = (u8 *)value;
u8 temp[4];
temp[0] = ptr[3];
temp[1] = ptr[2];
temp[2] = ptr[1];
temp[3] = ptr[0];
*value = temp;
}
.
- Follow-Ups:
- Re: Virtual Machine implementation problem, Please help me to spot the bug
- From: weidongtom@xxxxxxxxx
- Re: Virtual Machine implementation problem, Please help me to spot the bug
- References:
- Virtual Machine implementation problem, Please help me to spot the bug
- From: weidongtom@xxxxxxxxx
- Virtual Machine implementation problem, Please help me to spot the bug
- Prev by Date: Re: Question about comment parsing between C and C++ compiler
- Next by Date: Re: segmentation error
- Previous by thread: Re: Virtual Machine implementation problem, Please help me to spot the bug
- Next by thread: Re: Virtual Machine implementation problem, Please help me to spot the bug
- Index(es):
Relevant Pages
|