Thread: Run code from different arch

  1. #1
    Registered User
    Join Date
    May 2012
    Location
    Italy
    Posts
    53

    Run code from different arch

    I've developed a small (very small) ftp client and server.
    Both of these programs compile and run well only if they use the same arch.


    1. If client is Ubuntu amd64 and server is Ubuntu i386 i got a segfault (i think it is a pointer problem)
    2. If client is Ubuntu amd64 and server is Ubuntu amd64 all ok
    3. If client is Ubuntu i386 and server is Ubuntu i386 all ok

    How can i made these 2 programs working on different archs?
    It is a code problem? If so what i have to do?
    PS: i think it is a problem,for example, of pointer because they are 4 or 8 bytes based on the PC's arch!

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    More likely it is the different sizes of the int type then that of pointer being different sizes.

    Use the header stdint.h to define the types used to pass data from client to server.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    All FTP commands and replies are in plain text so there shouldn't be a problem with integer/pointer sizes between different architectures. It might help to look at the actual data being sent by the server and client with a packet sniffer like Wireshark. Make sure there isn't any binary data being transferred (except for the contents of a file transfer, of course).

  4. #4
    Registered User
    Join Date
    May 2012
    Location
    Italy
    Posts
    53
    Do you mean something like:
    Code:
    typedef int int32_t
    typedef unsigned int uint32_t

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > How can i made these 2 programs working on different archs?
    If you can post a small program which "works" on one machine, but crashes on another, then we can tell you where you're screwing up.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    May 2012
    Location
    Italy
    Posts
    53
    I have solved
    i have changed all of my size_t to uint32_t

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arch Linux, first install issues!
    By Annonymous in forum Linux Programming
    Replies: 4
    Last Post: 05-30-2012, 06:26 PM
  2. producing c/c++ code from flowcharts,pseudo code , algorithims
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2008, 07:09 AM
  3. Fibonacci, my arch enemy
    By StarOrbs in forum C++ Programming
    Replies: 9
    Last Post: 03-11-2005, 08:42 AM
  4. Having trouble translating psudeo-code to real-code.
    By Lithorien in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2004, 07:51 PM