64-bit and 32-bit C code on Solaris 10

On my Solaris 10 update 9 system, the following command gives:

#isainfo -b
64 

But if I create the following program in C with restrictions. h is on, I get:

#include <stdio.h>
#include <limits.h>

int main(void)
{ 
     printf("Maximum integer value on this system is = %d\n", INT_MAX);
}
gcc on64.c -o on64
./on64

Maximum integer value on this system is = 2147483647

I expected a much larger result, because the system runs on 64 bits. This looks like a 32 bit result. Is this a compiler problem?

+3
source share
7 answers

There are many programming models for 64-bit platforms, http://www.unix.org/version2/whatsnew/lp64_wp.html , including:

  • ILP64 (where int, long and pointers are 64-bit)
  • LP64 (where int is 32-bit and long and pointers are 64-bit)

64- Solaris 10 LP64 (http://www.sun.com/software/solaris/faqs/64bit.xml#q4):

Q: , Solaris?

A: LP64 - - . L P . 64-, int 32-.

"64- : LP64?" , , , Win64 LLP64, unix.org: http://blogs.msdn.com/b/oldnewthing/archive/2005/01/31/363790.aspx

+9

"int" - 32 gcc . "" - 32 32- 64 64- .

, C99:

#include <stdint.h>

int32_t i32;
int64_t i64;
+5

gcc documentation:

64- int 32 64 AMD x86-64 .

+1

, < <20 > :

#include <stdio.h>
#include <stdint.h>

int main(void)
{ 
     printf("Maximum integer value on this system is = %jd\n", INTMAX_MAX);
}

2 ^ 63 - 1.

+1

Solaris 10 32- 64-. 32-.

GCC, Sun, "-m32" "-m64" , . , :

$ gcc -m64 -o on64-64 on64.c
$ gcc -m32 -o on64-32 on64.c

:

$ file on64 on64-32 on64-64
...take a look see...
$ ./on64-64
...take a look see...
$ ./on64-32
...as you originally found...
$
+1

-, , 64- . 32- , 64- .

-, 64- , int 32-. GCC . , int, 64- 64- , .

, ( ). , , . Solaris 237- 1001- , GCC 32- , GCC .

0

"" (32 32- 64- 64- , "int", 32-),

printf("max long = %ld", LONG_MAX);

'-m64'

Max long on this system is: 9223372036854775807

'-m32'

Max long on this system is: 2147483647
0

Source: https://habr.com/ru/post/1768734/


All Articles