CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2007
    Posts
    90

    Compiler problem ?!

    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:

    Code:
    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.

  2. #2
    Join Date
    Aug 2005
    Location
    LI, NY
    Posts
    576

    Re: Compiler problem ?!

    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"?
    - Alon

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Compiler problem ?!

    Quote Originally Posted by BoSCHoW
    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

  4. #4
    Join Date
    Feb 2007
    Posts
    90

    Re: Compiler problem ?!

    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.

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Compiler problem ?!

    Quote Originally Posted by BoSCHoW
    I tested the program with Visual Studio and it work...then I copied the same program in cold fire and it does not work
    Different 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

  6. #6
    Join Date
    Feb 2007
    Posts
    90

    Re: Compiler problem ?!

    Do you have any recommendation on how to solve this problem ?

    Thanks and
    Best Regards,
    BoSCHoW.

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Compiler problem ?!

    Quote Originally Posted by BoSCHoW
    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

  8. #8
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: Compiler problem ?!

    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.

  9. #9
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Compiler problem ?!

    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?
    Last edited by S_M_A; March 26th, 2008 at 01:29 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured