slang-users mailing list

[2000 Date Index] [2000 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: Problems with structures in S-Lang


Goran Koruga <goran.koruga@xxxxxxxxx> wrote:
>/* here's the definition of the structure for S-Lang */
>static SLang_IStruct_Field_Type timeval_struct[] =
>{
>    MAKE_ISTRUCT_FIELD(struct timeval, sec,  "sec",  SLANG_UINT_TYPE, 1),
>    MAKE_ISTRUCT_FIELD(struct timeval, usec, "usec", SLANG_UINT_TYPE, 1),

I believe that `sec' and `usec' should be `tv_sec' and `tv_usec', resp.
Also, even though sizeof(long) == sizeof (int) on your 32 bit unix
system, you should use SLANG_LONG_TYPE for portability.

This example works for me:

#include <stdio.h>
#include <string.h>
#include <slang.h>
#include <stdlib.h>

#include <sys/time.h>
#include <unistd.h>

static struct timeval *Msl_timestamp; /* it's malloc'd in main() */

/* here's the definition of the structure for S-Lang */
static SLang_IStruct_Field_Type timeval_struct[] =
{
    MAKE_ISTRUCT_FIELD(struct timeval, tv_sec,  "sec",  SLANG_LONG_TYPE, 1),
    MAKE_ISTRUCT_FIELD(struct timeval, tv_usec, "usec", SLANG_LONG_TYPE, 1),
    SLANG_END_TABLE
};

/* here's how I set it */
void  Msl_set_timestamp(void)
{
   gettimeofday(Msl_timestamp, NULL);
}

int main (int argc, char **argv)
{
   (void) SLang_init_all ();
   (void) SLadd_istruct_table(timeval_struct, (VOID_STAR) &Msl_timestamp, "timestamp");

   Msl_timestamp = (struct timeval *) malloc (sizeof (struct timeval));
   Msl_set_timestamp ();

   SLang_load_file (argv[1]);

   return 0;
}


[2000 date index] [2000 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]