pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: {pkgsrc-users} need help with C# -- how to deal with different time_t widths?



Hi Matthias.

On 9-Sep-2009, at 11:41 AM, Matthias Drochner wrote:
The lower-case are the primitive types, and
the System.* are their corresponding classes; C# will automatically
box/unbox them as necessary.

What would be the advantage of using classes for integers?
Passing integers by reference doesn't sound very efficient.
(But anyway, since my problem is about modeling a C data
structure in C# I guess that simple types are the way to go.)

Even if you specify the classes, I don't think the instances are actually passed by reference: the actual instances aren't mutable. The notations simply interchangeable.

#if TIMET_IS_32BITS
     UInt32 blah;
#else
     UInt64 blah;
#endif

Thanks - this works.
Unfortunately, the assumption that time_t fits into a pointer
is also in exported interfaces of the underlying gtk-sharp
library, so I needed some typecasts to compensate.

So GTK# actually provide the time_t by casting it as a pointer?  Yuck.

I think a better fix would be to make the type used for
time_t a 64-bit integer throughout the code, but that
would be an interface change.
Could you please have a look at pkgsrc/x11/gnome-sharp and
check that my fix is correct?


I don't see any other way around it. I'm not a System.Runtime.Interop expert, but I can't see a way to describe such platform-specific knowledge. I don't know how the code could detect whether the platform has 64-bit time_t values.

So that looks like it will work in the short-term. These C# libraries won't be portable across platforms, but admittedly they weren't portable to NetBSD previously anyways :-)

I'm surprised this hasn't bitten people on 64-bit machine already though. Linux on amd64 seems to have time_t = 64 bits [*].

Brian.

[*] https://lists.isc.org/pipermail/dhcp-users/2006-May/000644.html

--
"Amusement to an observing mind is study." - Benjamin Disraeli



Home | Main Index | Thread Index | Old Index