Re: sizeof gpointer






On Tue, 20 Aug 2002, Olexiy Avramchenko wrote:

vladimir wrote:

Hi,
Great Free software developers!
I really need help on this one :)

i have:

    void func (gpointer data)
    {
        /* code ... */
    }

How can i get size of data in bytes ? 

The only one way I see is to pass a pointer to a structure like this:

typedef struct __my_fun_struct
{
        guint        size;        /* This's always the first field, 
initialized with data size. */
        gpointer   *data;     /* Or smth else you need */
} MY_FUN_STRUCT;


if I do sizeof ("text") i will get 5
if I do sizeof (255) i will get 4
if I do sizeof (12345678.987654321) i will get 8...

But if i do sizeof (data) i get crazy numbers :( (data is a gpointer) 

Hmm, crazy ? sizeof(gpointer) will return the constant number wich 
depends on your
architecture (== 4 for x86).

and 8 for alpha and sparc64, so be sure you're not counting on a fixed
value here if you want any sort of portability.

-dan





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]