GCC a velka cisla

Pavel Janoušek janousek na fonet.cz
Čtvrtek Listopad 27 09:52:50 CET 2003


	Zdravim po ranu,

	damy a panove, je schopen toto nekdo vyzkouset na GCC novejsi nez 3.0.4 v modu C99 a podelit se o vysledek?

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#define SIZE    5294967296L

int main (void)
{

  char *p = malloc ((size_t) SIZE);

  printf("%li\n", (long int) SIZE);
  printf("%lli\n", (long long) SIZE);
  if (p == NULL)
  {
    perror ("malloc");
    return (0);
  }

  getchar ();

  free (p);

  return (0);
}

Kolega Ovsik mi napsal, ze:

Info ke gcc se pise:
--------------------<snip>--------------------
Double-Word Integers
====================

   ISO C99 supports data types for integers that are at least 64 bits
wide, and as an extension GCC supports them in C89 mode and in C++.
Simply write `long long int' for a signed integer, or `unsigned long
long int' for an unsigned integer.  To make an integer constant of type
`long long int', add the suffix `LL' to the integer.  To make an
integer constant of type `unsigned long long int', add the suffix `ULL'
to the integer.
...
--------------------<snip>--------------------

	Tedy v C99 to zrejme je (long long). 

	gcc pise warning v modu C89.

Moje gcc debianu jeste neumi -std=c99, ale ve woody je jeste gcc-3.0.
A to se chova trosku jinak (stejny kod)

zito na bobek big-int $ gcc-3.0 -Wall -pedantic big.c 
big.c:6:1: warning: C++ style comments are not allowed in ISO C89
big.c:6:1: warning: (this will be reported only once per input file)
big.c: In function `main':
big.c:11: warning: integer constant larger than the maximum value of an unsigned long int
big.c:13: warning: integer constant larger than the maximum value of an unsigned long int
big.c:14: warning: integer constant larger than the maximum value of an unsigned long int
big.c:14: warning: ISO C89 does not support `long long'
big.c:14: warning: ISO C89 does not support the `ll' printf length modifier


zito na bobek big-int $ gcc-3.0 -Wall -pedantic -std=c99 big.c 
zito na bobek big-int $ 

Tedy v modu C99 skutecne nezarve vubec. Coz je ovsem otazkam, jestli
todle neni chyba (zrejme taky ponekud obsoletni verze gcc 3.0)

zito na bobek big-int $ gcc-3.0 --version
3.0.4

	A ted ja (PaJaSoft):

	Podstatne je, ze v modu C99 spokojene NEOHLASI zadny warning (i s -pedantic) a to i v pripade, kdy se to IMHO do daneho typu nevejde... - nebo snad C99 (coz sice nevim, ale zatim neverim) sizeof(long int) zvetsuje oproti C89 na dvojnasobek?

	Pokud ani novejsi GCC (> 3.0.4) nehlasi warning je to feature nebo chyba GCC v tomto modu?

-------------------------------------------------------------------
Ing. Pavel Janousek (PaJaSoft)             FoNet, spol. s r. o.
Technicka podpora, Intranet/Internet     Sokolova 67, 619 00 Brno
E-mail: mailto:Janousek na FoNet.Cz         Tel.: +420  5  4324 4749
WWW:    http://WWW.FoNet.Cz/           E-mail: mailto:Info na FoNet.Cz
-------------------------------------------------------------------


Další informace o konferenci Linux