Subject: Problem with libgtop2
To: None <tech-userlevel@NetBSD.org>
From: Julio M. Merino Vidal <jmmv@menta.net>
List: tech-userlevel
Date: 04/12/2004 14:49:13
Hi all,
[ posting to -userlevel because this is not exactly a packages question ]
I've found a problem in libgtop2, where it doesn't pass parameters correctly
between some functions. Consider the following test case (which, aside from
the 'buf' thing does the same as libgtop2):
#include <sys/types.h>
#include <stdio.h>
void foo(void *ptr)
{
int64_t *params = (int64_t *)ptr;
printf("arg1: %d\n", params[0]);
printf("arg2: %d\n", params[1]);
}
void func(int64_t a, int64_t b)
{
int64_t buf[2];
foo((void *)&a); /* This is what libgtop does */
buf[0] = a;
buf[1] = b;
foo((void *)&buf);
}
int main(void) {
func((int64_t) 10, (int64_t) 20);
return 0;
}
Which outputs:
arg1: 10
arg2: 1208273232
arg1: 10
arg2: 20
Note the second line, which shows an incorrect value, just like libgtop2.
Using 'long' instead of int64_t, works. This same program works properly
under linux.
What's happening here? I can't figure it out :(
Thanks.
--
Julio M. Merino Vidal <jmmv@menta.net>
The NetBSD Project - http://www.NetBSD.org/