Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #158329

Re: I need help understand struct defination

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: I need help understand struct defination
Date 2021-01-12 23:41 +0000
Organization A noiseless patient Spider
Message-ID <87lfcxsoyn.fsf@bsb.me.uk> (permalink)
References <rtl0tf$9p6$1@dont-email.me> <87r1mpsuf5.fsf@bsb.me.uk> <rtl95k$qm2$1@dont-email.me>

Show all headers | View raw


T <T@invalid.invalid> writes:

> On 1/12/21 1:43 PM, Ben Bacarisse wrote:
>> What do you intend to do with it when you find out?
>
> I intend to create a class that duplicates the structure.
> Then create a pointer to an object of the class.

I think you are missing what people are saying.  Bottom line, you can't
do that so you should stop trying.  Back up a bit...  If your goal is
use the GTK API from Perl6, you don't need to know what is in this
struct.  All you need is a pointer type you can get from the API and
pass to the other API functions.

> Looks like this:
>
>
> C:
>
> struct_tm
> {
>   int tm_sec;			/* Seconds.	[0-60] (1 leap second) */
>   int tm_min;			/* Minutes.	[0-59] */
>   int tm_hour;			/* Hours.	[0-23] */
>   int tm_mday;			/* Day.		[1-31] */
>   int tm_mon;			/* Month.	[0-11] */
>   int tm_year;			/* Year	- 1900.  */
>   int tm_wday;			/* Day of week.	[0-6] */
>   int tm_yday;			/* Days in year.[0-365]	*/
>   int tm_isdst;			/* DST.		[-1/0/1]*/
>
> # ifdef	__USE_MISC
>   long int tm_gmtoff;		/* Seconds east of UTC.  */
>   const char *tm_zone;		/* Timezone abbreviation.  */
> # else
>   long int __tm_gmtoff;		/* Seconds east of UTC.  */
>   const char *__tm_zone;	/* Timezone abbreviation.  */
> # endif
> };
>
> #endif
>
>
> Raku:
>
> class tm is repr('CStruct') {
>    has int32   $.tm_sec;			  # Seconds.	[0-60] (1 leap second)
>    has int32   $.tm_min;		  	# Minutes.	[0-59]
>    has int32   $.tm_hour;  		# Hours.	[0-23]
>    has int32   $.tm_mday;	  	# Day.		[1-31]
>    has int32   $.tm_mon;  			# Month.	[0-11]
>    has int32   $.tm_year;	  	# Year	- 1900.   Add 1900 to this to get a four digit year
>    has int32   $.tm_wday; 	 	# Day of week.	[0-6]
>    has int32   $.tm_yday;		  # Days in year.[0-365]
>    has int32   $.tm_isdst;	  # DST.		[-1/0/1]
>    has int64   $.tm_gmtoff;		# Seconds east of UTC.
>    has byte    $.tm_zone;    # Timezone abbreviation.

This is a different kind of structure.  You are supposed to look
inside.

It is very common for an API to use an opaque type -- one you can't
"look inside".  The only code that can use it is the implementation of
that API.

-- 
Ben.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

I need help understand struct defination T <T@invalid.invalid> - 2021-01-12 12:30 -0800
  Re: I need help understand struct defination Anton Shepelev <anton.txt@gmail.com> - 2021-01-12 23:48 +0300
  Re: I need help understand struct defination Bart <bc@freeuk.com> - 2021-01-12 21:38 +0000
    Re: I need help understand struct defination Bart <bc@freeuk.com> - 2021-01-12 21:55 +0000
      Re: I need help understand struct defination T <T@invalid.invalid> - 2021-01-12 14:26 -0800
        Re: I need help understand struct defination Bart <bc@freeuk.com> - 2021-01-12 22:32 +0000
        Re: I need help understand struct defination antispam@math.uni.wroc.pl - 2021-01-12 22:49 +0000
  Re: I need help understand struct defination Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-01-12 21:43 +0000
    Re: I need help understand struct defination T <T@invalid.invalid> - 2021-01-12 14:51 -0800
      Re: I need help understand struct defination Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-01-12 23:41 +0000
        Re: I need help understand struct defination T <T@invalid.invalid> - 2021-01-12 17:50 -0800
  Re: I need help understand struct defination antispam@math.uni.wroc.pl - 2021-01-12 22:30 +0000

csiph-web