Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #3217 > unrolled thread
| Started by | bob <bob@coolfone.comze.com> |
|---|---|
| First post | 2013-04-02 13:58 -0700 |
| Last post | 2013-04-03 16:42 +0200 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.programming
64 bit check? bob <bob@coolfone.comze.com> - 2013-04-02 13:58 -0700
Re: 64 bit check? Ian Collins <ian-news@hotmail.com> - 2013-04-03 10:09 +1300
Re: 64 bit check? Robert Wessel <robertwessel2@yahoo.com> - 2013-04-03 01:14 -0500
Re: 64 bit check? Jongware <jongware@no-spam.plz> - 2013-04-03 16:42 +0200
| From | bob <bob@coolfone.comze.com> |
|---|---|
| Date | 2013-04-02 13:58 -0700 |
| Subject | 64 bit check? |
| Message-ID | <bfd869a1-e70f-448b-9cf5-6107309a4366@googlegroups.com> |
Is this a foolproof way to check if your code is running in 64 bit mode? int pointer_size = sizeof(int*); boolean sixty_four_bit = (pointer_size==8) ? true : false; Thanks.
[toc] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2013-04-03 10:09 +1300 |
| Message-ID | <as0vo4Fbg77U3@mid.individual.net> |
| In reply to | #3217 |
bob wrote: > Is this a foolproof way to check if your code is running in 64 bit mode? > > int pointer_size = sizeof(int*); > boolean sixty_four_bit = (pointer_size==8) ? true : false; Define a constant at compile time based on the compiler's built in flags. -- Ian Collins
[toc] | [prev] | [next] | [standalone]
| From | Robert Wessel <robertwessel2@yahoo.com> |
|---|---|
| Date | 2013-04-03 01:14 -0500 |
| Message-ID | <9bhnl8d2oj5398s81d6sv926kbk8dl104h@4ax.com> |
| In reply to | #3217 |
On Tue, 2 Apr 2013 13:58:38 -0700 (PDT), bob <bob@coolfone.comze.com> wrote: >Is this a foolproof way to check if your code is running in 64 bit mode? > >int pointer_size = sizeof(int*); >boolean sixty_four_bit = (pointer_size==8) ? true : false; Nope. What if chars are bigger than eight bits? What if addresses are not 64 bits? While you might have difficulties finding exactly such systems, example of that sort of oddness have existed. Consider the memory models for 16 bit x86 code. Pointers could be either 16 or 32 bits in length, and code and data pointers could be different sizes. Some implementations have much additional data in the pointers, for example, on some AS/400 implementations, despite being a 48 or 64 bit machine, pointers might be up to 64 bytes long. Or how do you classify programs that run using the x32 ABI, where the code is x86-64, but only 32 bits of pointers are stored?
[toc] | [prev] | [next] | [standalone]
| From | Jongware <jongware@no-spam.plz> |
|---|---|
| Date | 2013-04-03 16:42 +0200 |
| Message-ID | <515c3fd5$0$6889$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #3217 |
On 02-Apr-13 22:58 PM, bob wrote:
> Is this a foolproof way to check if your code is running in 64 bit mode?
>
> int pointer_size = sizeof(int*);
> boolean sixty_four_bit = (pointer_size==8) ? true : false;
If your compiled code is running on a 64-bit CPU emulator (say, in
current CPU design software; or, in 20 years time, to emulate vintage
systems), should it return 'true' or 'false'? I think either answer
might be possible ...
Anyway, as has been pointed out, the question is irrelevant because you
have to *compile* it for '64-bit mode' OR for '32-bit mode'. So -- with
all #defines et cetera resolved -- the actual code that gets compiled
boils down to
boolean isSixtyFourBit (void)
{
return true;
}
[Jw]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.programming
csiph-web