473,395 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

"long" in C#

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);
}

Feb 20 '07 #1
3 7285
On Feb 19, 9:17 pm, "ext" <e...@comcast.comwrote:
"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.

Feb 20 '07 #2
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 20 '07 #3

"Bruce Wood" <br*******@canada.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
>
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.
May 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Num | last post by:
Hi all, I have to convert a J2EE date as a long ("Millis") in a .NET date as a long ("Ticks") In Java, currentTimeMillis, is the difference, measured in milliseconds, between the current time...
17
by: Adam Ierymenko | last post by:
I have a question that might have been asked before, but I have not been able to find anything via groups.google.com or any web search that is definative. I am writing an evolutionary AI...
6
by: Otto Wyss | last post by:
I've the following function declaration: wxTree GetLastChild (const wxTree& item, long& cookie) const; I'd like to make the cookie parameter optional, i.e. "long& cookie = ....", without...
16
by: ondekoza | last post by:
Hello, I need to convert the string "FFFFFFFF" to a long. To convert this string I tried the following: >>> 0xffffffff -1 >>> 0xffffffffL 4294967295L OK, this is what I want, so I tried
12
by: Zero | last post by:
Hi everybody, i want to write a small program, which shows me the biggest and smallest number in dependance of the data type. For int the command could be: ...
0
by: Curious | last post by:
Hi, I have two columns defined as DateTime type in the Visual Designer, i.e., Dataset.xsd. In the grid to which the columns are bound, they're both displayed as date, for instance, 5/23/2007....
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.