473,729 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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 7297
On Feb 19, 9:17 pm, "ext" <e...@comcast.c omwrote:
"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*******@cana da.comwrote in message
news:11******** **************@ v33g2000cwv.goo glegroups.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
3627
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 and midnight, January 1, 1970 UTC. In .NET, DateTime.Ticks is the 100-nanosecond intervals that have
17
3943
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 application in C++. I want to use 32-bit integers, and I want the application to be able to save it's state in a portable fashion. The obvious choice would be to use the "long" type, as it is deined to be at least 32 bits in size. However, the...
6
2612
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 breaking any software using the old API. The implementation looks like wxTree wxTreeListMainWindow::GetLastChild (const wxTree& item, long& cookie) const {
16
3780
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
43451
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: printf("\n%20s\t%7u\t%13i\t%13i","signed int",sizeof(signed int),INT_MIN,INT_MAX);
0
2152
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. It seems that they're using the default "short date" format. I want to use the "long date" format to display the actual hour/minute/
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9142
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.