"long" in C#

E

ext

"A "long" in C is an "int" in C#."

Does this mean that whenever passing a parameter to a C function which
expects a long type, the variable on C# side should be declared as int type?

What if in the following case, should the parameter "level" be type of int
as well?

public interface XoInterface
{
...

int get_Level(out long level);
}
 
B

Bruce Wood

"A "long" in C is an "int" in C#."

Does this mean that whenever passing a parameter to a C function which
expects a long type, the variable on C# side should be declared as int type?

What if in the following case, should the parameter "level" be type of int
as well?

public interface XoInterface
{
...

int get_Level(out long level);



}

For the most part, yes.

In theory, this isn't always so: in C, "int" and "long" were never
given a fixed definition. "int" was "the most convenient size for the
processor" and long was "bigger than that". I think that there were
minimums (16 and 32 bits, respectively) but I could be wrong about
that.

In C#, "int" and "long" have fixed definitions (32 and 64 bits,
respectively) regardless of the machine on which they're running.

Technically speaking, if your C is compiled on a 32-bit system, int
and long will both be 32 bits. If your C is compiled on a 64-bit
system, int and long may be 64 bits (I'm not sure).

However, since C# is practically limited to WinTel machines (with the
exception of Mono), all you have to worry about is what's going on in
that world. Again, the interpretation of int and long in C may be
changing as a result of the changeover from 32-bit to 64-bit
architecture, so be careful.
 
M

Mattias Sjögren

If your C is compiled on a 64-bit
system, int and long may be 64 bits (I'm not sure).

Not in Microosft's compilers - they remain 32 bits.


Mattias
 
M

Mike Schilling

In theory, this isn't always so: in C, "int" and "long" were never
given a fixed definition. "int" was "the most convenient size for the
processor" and long was "bigger than that".

Nit: long is "as least as big as that." There are many C compilers with int
== long == 32 bits.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top