I have a code that receives binary array of 32-bit values from a device and prints them with vsprintf, like this:
void print_stuff(int32_t *p, const char *format)
{
vprintf( format, (va_list)p);
}
(this is simplified; it's ensured that the values match the format, etc.)
Basically this relies on that in normal x86 va_list is just a pointer (or array). This compiles without warnings.
Now I need to port this to ARM (arm-linux-gnueabihf) and x64, and it does not even compile. GCC 4-something for ARM says "error: conversion to non-scalar type requested"
How to make a va_list from a binary array in a portable way? Or at least for 32-bit and 64-bit archs separately - is possible without any "native call interface" libraries? If this is impossible, then is there any other standard or GNU library function suitable for this task?
Example of code that calls this:
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#ifndef __GNUC__
#error Only Linux, other platforms/compilers not needed
#endif
int main() {
uint32_t data[10];
int i;
const char *fmt = "%x %x %x %x\n";
// Simulation of reading the data
for(i = 0; i < 10, i++) data[i] = 0x100 + i;
print_stuff(data, fmt);
return 0;
}