Page 1 of 1

sizeof(int)

PostPosted: Wed May 16, 2012 3:48 am
by _Alex_
Hi,

I am trying to find equivalent of C# sizeof(int).

Is this it ?
Code: Select all
Cobra.Lang.NumericTypeInfo(int).size

Re: sizeof(int)

PostPosted: Wed May 16, 2012 12:31 pm
by Charles
We don't have anything right now, so you'll have to use the escape hatch:
class X

def main
assert sharp'sizeof(int)' == 4

For the basic types, their sizes are fixed so it's not all that interesting. But C#'s sizeof is handy to get the total size of a struct if you need it for some reason.

Re: sizeof(int)

PostPosted: Wed May 16, 2012 12:56 pm
by DelphiGuy
"sharp"?

couldn't find it in cobra keywords. what is it, please? just the syntax to use to pass something through to the C# backend unchanged? is this documented somewhere on the cobra website?

thanks.

Re: sizeof(int)

PostPosted: Wed May 16, 2012 1:07 pm
by Charles
Yep, I call them "sharp strings" and we use them when there is something you need from C# that you don't have in Cobra. This doesn't come up too often these days.

The Cobra compiler is written in Cobra and has 49,132 raw lines of code. There are less than 40 sharp strings in that code base and I think several of them can be removed either now or after making a new "snapshot compiler".

They've been discussed in this forum, but I don't see them in the wiki.

Re: sizeof(int)

PostPosted: Wed May 16, 2012 1:14 pm
by Charles
Here is some information on computing size in .NET:
Computing the Size of a Structure
by Jim Mischel

A while back, I needed some C# code that would determine how much memory an array of a generic type would take. This turns out to be a lot more complicated than I at first thought it would be, because object size can be difficult to determine. Let me start at the beginning.
...

http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=698

Re: sizeof(int)

PostPosted: Thu May 17, 2012 1:22 am
by hopscc
Its mentioned ( very briefly) under Strings and Characters under the 'Platform' subsection.

Admittedly not very easy to find, obvious or clear.

(DelphiGuy) What would you like to see and how do you think this should be described?