I am working on a chat client and server. I currently have this line in my server for debugging purposes:
printf("Message for %s:\nTimestamp: %ld, Message: %s, Length: %d\n", args->name, *(int64_t*)(message->data), message->data+8, message->length);
args->name
contains a char*
to a normal null-terminated string and message is a struct string*:
struct string
{
char* data;
uint32_t length;
uint32_t capacity;
};
In this case, the first 8 byte are a posix timestamp, the rest is just a null-terminated string.
If I compile with -m64
I get this output:
Message for some_user:
Timestamp: 1512060499, Message: >Server1@some_user:test, Length: 32
But compiling with -m32
yields this output:
Message for some_user:
Timestamp: 1512060650, Message: (null), Length: 69823144
Now the message is transferred to the client via a function containing this line:
write(socket_fd, message->data, message->length)
The really weird thing is, the message arrives at the client completely fine. I get exactly the same output on the client side.
Am I using the printf function wrong somehow?