/* main_ptr.c - consumer compiled against the v1 pointer layout.
 * Build: gcc -o app_ptr main_ptr.c -L. -lgpuptr
 * Run:   LD_LIBRARY_PATH=. ./app_ptr
 *
 * This binary believes:  gpu_id@0, temperature@4, name@8.
 * Against v1 it prints the right thing.
 * Against v2_ptr_bad, offset 8 holds the integer 42 (plus 99 in the next
 * 4 bytes), so `name` becomes the address 0x000000630000002a -> segfault.
 */
#include <stdio.h>

struct gpu_info {
    int gpu_id;
    int temperature;
    const char *name;
};

extern void gpu_info_get(struct gpu_info *info);

int main(void) {
    struct gpu_info info = {0};
    gpu_info_get(&info);

    printf("gpu_id=%d temperature=%d\n", info.gpu_id, info.temperature);
    printf("name pointer = %p\n", (void *)info.name);
    fflush(stdout);

    printf("name = %s\n", info.name);   /* <-- dereference happens here */
    return 0;
}
