Forums

sizeof(int)

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

sizeof(int)

Postby _Alex_ » Wed May 16, 2012 3:48 am

Hi,

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

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

Re: sizeof(int)

Postby Charles » Wed May 16, 2012 12:31 pm

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: sizeof(int)

Postby DelphiGuy » Wed May 16, 2012 12:56 pm

"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.
DelphiGuy
 
Posts: 116

Re: sizeof(int)

Postby Charles » Wed May 16, 2012 1:07 pm

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: sizeof(int)

Postby Charles » Wed May 16, 2012 1:14 pm

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
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: sizeof(int)

Postby hopscc » Thu May 17, 2012 1:22 am

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?
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand


Return to Discussion

Who is online

Users browsing this forum: No registered users and 43 guests