Click to See Complete Forum and Search --> : Compiler problem ?!
BoSCHoW
March 25th, 2008, 11:12 AM
Hello,
today while working on ColdFire microchip with Freescale Codewarrior 6.4 I encountered a problem.
Lets say one function is composed of other functions, and when I compile the code it seems like
that this other functions aren't included in the output file.
This functions are used for separating bytes from an short or a long in and to merge 2 bytes into a short and 4 bytes into a long int. The sample code could be seen below:
UINT16 convert_two_bytes_to_UINT16(UINT8 *bytes)
{ UINT16 result = bytes[0];
result <<= 8;
result |= bytes[1];
return result;
}
When I use this function in the main function, in the neverending loop the function works and the return value corresponds to the value of 2 bytes.
I don't know what do to, so if somebody had simmilar problems I cindly ask them for some help.
Thanks and best regards,
BoSCHoW.
Hermit
March 25th, 2008, 11:22 AM
I'm not all that clear on what the problem is (but I doubt it's the compiler). Is the function returning garbage values in some context? What do you mean by "not included in the output file"?
Paul McKenzie
March 25th, 2008, 11:26 AM
Lets say one function is composed of other functions, and when I compile the code it seems like
that this other functions aren't included in the output file.I don't know what you're trying to say here. What do you mean by "incuded in the output file"?
You compile a source file, you get object code. Then the linker links the object code to get an executable. Where in these steps is your reference to an "output file"?
Regards,
Paul McKenzie
BoSCHoW
March 25th, 2008, 11:52 AM
I meant that the function is not included maybe in the object file or in the executable.
I tested the program with Visual Studio and it work...then I copied the same program in cold fire and it does not work ... and I don't know what could be the cause of the error.
What I try to achieve:
I am just using TCP IP communication protocol. For communication uses a stream of bytes. The 10 and the 11 byte tells me the length of the package.
In this case I am using the function from my previous post. I know that is shouldn't return 0 but still it does.
Thanks for the help,
Best Regards,
BoSCHoW.
Paul McKenzie
March 25th, 2008, 11:59 AM
I tested the program with Visual Studio and it work...then I copied the same program in cold fire and it does not workDifferent architectures, different compilers, bad or improper coding on your part, who knows. We certainly don't know, unless you post the program you say doesn't work.
Also, just because a program "works" when compiled with one compiler and "fails" on another is not an indication there is something wrong with the compiler. In all likelihood, you've coded something that by chance works for one compiler, but when you look at the code, the code was not guaranteed to work on *all* compilers and platforms correctly.
Regards,
Paul McKenzie
BoSCHoW
March 25th, 2008, 12:37 PM
Do you have any recommendation on how to solve this problem ?
Thanks and
Best Regards,
BoSCHoW.
Paul McKenzie
March 25th, 2008, 01:17 PM
Do you have any recommendation on how to solve this problem ?Just like any other program that doesn't work -- you debug it with the tools that you have available.
Regards,
Paul McKenzie
Richard.J
March 25th, 2008, 04:03 PM
sounds like a byte-order problem. Different architectures have different byte orders. You might want to lookup ntohs and ntohl to see if this helps to solve your problem.
S_M_A
March 25th, 2008, 04:42 PM
BoSCHoW, didn't your other threads regarding converting network streams into platform specific 16-bit & 32-bit byte order convince you that htons/htonl/ntohs/ntohl is the safe way to handle these issues? ;)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.