Asterism
Asterism

Reputation: 21

C: Turning ints into char* buffers?

I'm working on a strange little embedded platform that seems to have undefined behavior when calling their POSIX-compliance functions with source pointers that are anything other than a char*. It's kind of a stupid workaround, but how would I go about converting an int in C to a character buffer with the same bit ordering?

For example:

int foo = 15;
turning into
char* bar = "\x00\x0F\x00\x00";

Upvotes: 2

Views: 114

Answers (1)

nmichaels
nmichaels

Reputation: 50941

Use this method:

function((char *)&bar)

Upvotes: 5

Related Questions