What is the best / most canonical way to pass in a constant integer value to a function waiting for a pointer?
For example, the function write
write (int filedes, const void *buffer, size_t size);
Say I just want to write one byte (a 1), I would think about this:
write (fd, 1, 1);
but I obviously get a warning
warning: passing argument 2 of 'write' makes pointer from integer without a cast
I know what I can do
int i = 1;
write (fd, &i, 1);
but is it necessary? What is the best way to do this without having to declare / initialize a new variable?
source
share