Re: VS2005 doesn't like its own suggestions
- From: "Lawrence Groves" <lgroves@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 22 Jul 2005 08:43:08 +0100
"John Carson" <jcarson_n_o_sp_am_@xxxxxxxxxxxxxxx> wrote in message
news:Oz4UBdjjFHA.3568@xxxxxxxxxxxxxxxxxxxxxxx
> "Lawrence Groves" <lgroves@xxxxxxxxxxxxxxxxxxx> wrote in message
> news:%237YEUwfjFHA.2152@xxxxxxxxxxxxxxxxxxxx
>> "Hendrik Schober" <SpamTrap@xxxxxx> wrote in message
>> news:OURnEQfjFHA.3336@xxxxxxxxxxxxxxxxxxxxxxx
>>> Nishant Sivakumar <nish@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
>>>> Hello Hendrik
>>>>
>>>>> How would my programs become more portable if
>>>>> I used 'INT' instead of 'int'?
>>>>
>>>> INT is a Win32 API type, while int is a C/C++ type. Using INT
>>>> (supposedly)
>>>> guarantees portability across all versions of Windows.
>>>
>>> Ugh. I wouldn't have considered this to be
>>> portability.
>>
>> Nor would I!!!
>>
>> But I think the answer to your original question is that since INT
>> has a fixed size (32 bits) a program can be written in that knowledge
>> and then ported to a different arcitecture. 'int' has no such
>> guarentees. Its size is not fixed across platforms/compilers.
>>
>> Imaging you move your INT code to a 64 bit platform and rebuild. You
>> might find that on the 32 bit system this is what is defined:
>>
>> typedef int INT;
>>
>> but on the 64 bit system it could be:
>>
>> typedef short INT;
>>
>> The point is, they both ensure that INT is 32 bits and your program
>> will compile and run the same on both platforms. The use of 'int' in
>> your program would potentially give you grief because its is
>> (probably) 64 bits instead of 32.
>
> If you go to the online MSDN library, you see that INT is indeed specified
> to be 32 bits.
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/windows_data_types.asp
>
> However, if I look at the MSDN library that came with VC++ 6.0, then INT
> is
> described simply as a "signed integer". If I look at the list of data
> types
> for MFC in the same MSDN library, there is no explicit mention of INT, but
> UINT is described as "A 16-bit unsigned integer on Windows versions 3.0
> and
> 3.1; a 32-bit unsigned integer on Win32."
>
> Both then and now, INT is actually a typedef for int and UINT is a typedef
> for unsigned int.
>
> From this I conclude the following:
>
> 1. INT/UINT were never designed to give a guarantee of a particular size.
> They were simply aliases for int/unsigned int. The appearance of
> guarantees
> in the current documentation is simply because int/unsigned int are 32 bit
> under both Win32 and Win64 and Microsoft is looking no further ahead than
> Win64 and no further back than Win32.
>
> 2. The rationale for using INT/UINT typedefs was never specific. It was
> just
> based on the general principle that if you use typedefs rather than
> hard-coded types, then you can map those typedefs to whatever is most
> convenient for the platform you are targetting. As things have turned out
> ex
> post, using INT/UINT has been no different to using int/unsigned int.
Ok, so its not specific enough in the documentation, or at least its been
amended to say what was CONCEPTUALLY always meant. As an example, how big
are these:
BYTE
WORD
Now you can argue till the cows come home that a byte might not always be
eight bits on all systems, but I wouldn't mind betting that you'de be hard
pushed to find a Windows system where this wasn't the case.
Loz.
.
- Follow-Ups:
- Re: VS2005 doesn't like its own suggestions
- From: John Carson
- Re: VS2005 doesn't like its own suggestions
- From: Hendrik Schober
- Re: VS2005 doesn't like its own suggestions
- References:
- VS2005 doesn't like its own suggestions
- From: David F
- Re: VS2005 doesn't like its own suggestions
- From: Carl Daniel [VC++ MVP]
- Re: VS2005 doesn't like its own suggestions
- From: David F
- Re: VS2005 doesn't like its own suggestions
- From: Nishant Sivakumar
- Re: VS2005 doesn't like its own suggestions
- From: David F
- Re: VS2005 doesn't like its own suggestions
- From: Simon Watson
- Re: VS2005 doesn't like its own suggestions
- From: David F
- Re: VS2005 doesn't like its own suggestions
- From: Carl Daniel [VC++ MVP]
- Re: VS2005 doesn't like its own suggestions
- From: David F
- Re: VS2005 doesn't like its own suggestions
- From: Hendrik Schober
- Re: VS2005 doesn't like its own suggestions
- From: Nishant Sivakumar
- Re: VS2005 doesn't like its own suggestions
- From: Hendrik Schober
- Re: VS2005 doesn't like its own suggestions
- From: Lawrence Groves
- Re: VS2005 doesn't like its own suggestions
- From: John Carson
- VS2005 doesn't like its own suggestions
- Prev by Date: Re: Enabling Memory Leak Detection
- Next by Date: Re: VS2005 doesn't like its own suggestions
- Previous by thread: Re: VS2005 doesn't like its own suggestions
- Next by thread: Re: VS2005 doesn't like its own suggestions
- Index(es):
Relevant Pages
|