Re: question C

Top Page

Reply to this message
Author: Philippe FAVIER
Date:  
To: guilde
Subject: Re: question C
Edgar Bonet Orozco wrote:
>
> Salut !
>
> > #include <stdio.h>
> >
> > int main(argc, argv)
> > int argc;
> > char** argv;
>
> Tiens, tu écris encore le C avec l'accent K&R ?
>
> > {
> >         char c;

> >
> >         c = -32;
> >         printf("%ld\n", (long)c);
> >       return 0;
> > }

> >
> > Les resultats sont les suivant:
> >
> > AIX(PowerPC): 224
> > Linux(PowerPC):       224
> > Linux(Intel): -32

> >
> > Le resultat logique me semble etre -32.
> > (Le bit de signe devrait etre etendu de char
> > vers long).
> >
> > Qu'en pensez-vous ?
>
> Qu'il faut écrire « signed char » ou « unsigned char » si on veut faire
> des choses comme ça. « Le fait que les variables de type char tout court
> soient signées ou non dépend de la machine utilisée », K&R, 2e édition,
> p.36 de la version française.
>
> > Qu'en est-il sur d'autres systemes
> > (Sparc, SGI, Cray :-) ) ?
>
> Linux(Sparc), SunOS(Sparc) et HP-UX 9(HP) : -32
>
> Tiens, le compilateur C de la HP est comique. J'ai remis le programme en
> C ANSI et il me dit :
>         error 1705: Function prototypes are an ANSI feature.
> Faudra lui expliquer ce que le mot « error » veut dire...



Pour comprendre ce que error veut dire: man cc.

cc peut fonctionner dans plusieurs modes. Par defaut, il prend le mode
K&R.
Pour compiler en mode ANSI, utiliser l'option -Aa.


Voici un extrait de man cc:

      -Amode         Specify the compilation standard to be used by the
                     compiler.  mode can be one of the following
letters:


                        c    (Default) Compile in a mode compatible with
                             HP-UX releases prior to 7.0.  (See The C
                             Programming Language, First Edition by
                             Kernighan and Ritchie).  This option also
                             defines the symbol _HPUX_SOURCE and allows
the
                             user to access macros and typedefs provided
by
                             the HPUX Operating System. The default
                             compilation mode may change in future
releases.


                        a    Compile under ANSI mode (ANSI programming
                             language C standard ISO 9899:1990).  When
                             compiling under ANSI mode, the header files
                             would define only those names (macros and
                             typedefs) specified by the Standard. To
access
                             macros and typedefs that are not defined by
the
                             ANSI Standard but are provided by the HPUX
                             Operating System, define the symbol
                             _HPUX_SOURCE; or use the extension option
                             described below.


                        e    Extended ANSI mode.  Same as -Aa
-D_HPUX_SOURCE
                             +e.  This would define the names (macros
and
                             typedefs) provided by the HPUX Operating
System
                             and, in addition, allow the following
                             extensions: $ characters in identifier
names,
                             sized enums, sized bit-fields, and 64-bit
                             integral type long long.  Additional
extensions
                             may be added to this option in the future.



Phil.


> Edgar.


--


________________________________________________________________________
Philippe FAVIER                                   Hewlett-Packard
loc:   B1N2/B3                               5, avenue Raymond Chanas
tel:   +33 (0)4 76 14 43 77                        38053 Eybens
email: pfavier@???               France
________________________________________________________________________