comp.lang.ada
 help / color / mirror / Atom feed
From: "Björn Persson" <spam-away@nowhere.nil>
Subject: Re: Error-names.
Date: Sun, 07 Mar 2004 15:10:55 GMT
Date: 2004-03-07T15:10:55+00:00	[thread overview]
Message-ID: <3YG2c.85332$dP1.238856@newsc.telia.net> (raw)
In-Reply-To: <5tibh1-m92.ln1@martinkl.dialup.fu-berlin.de>

Martin Klaiber wrote:

> BTW: does someone know why these constants are not recognized by the
> C-program as constants?  They are declared as constants and in the C
> header-file I put:
> 
>    /* error-codes */
> 
>    extern const int no_error_code;
>    extern const int general_error_code;
>    ...
> 
> But if I want to use it in a switch-command like that:
> 
>    int year;
>    ...
>    for (year = 2003; year <= 2005; ++year) {
>       switch (set_year (year)) {
>       case no_error_code :
>          set_lzz (1);
>          ...
>                          
> the compiler says:
> 
>    test_c.c:20: case label does not reduce to an integer constant
> 
> Is my exporting wrong?  Or is this a C-problem?  When I use "case 0"
> instead of "case no_error_code" it works ok, but this is what I want
> to avoid.

As I understand it, "const" in C doesn't give you a constant. You get 
kind of a read-only variable. You can't change its value, but it's still 
treated as a variable and not allowed where a constant is required.

Put another way, where the language requires a constant it actually 
requires a literal, not a named constant.

I suppose this is why everyone uses preprocessor macros for constants, 
since they are translated to literals.

Yet another reason to loathe C ...

-- 
Björn Persson

jor ers @sv ge.
b n_p son eri nu




  reply	other threads:[~2004-03-07 15:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-28 12:58 Error-names Martin Klaiber
2004-02-28 13:35 ` Error-names Martin Dowie
2004-02-28 15:26   ` Error-names Martin Klaiber
2004-02-28 17:19     ` Error-names Marius Amado Alves
2004-02-28 18:31       ` Error-names Martin Klaiber
2004-02-28 19:47         ` Error-names tmoran
2004-02-28 20:29           ` Error-names Martin Klaiber
2004-02-29 19:03           ` Error-names Jeffrey Carter
2004-02-29 20:04             ` Error-names tmoran
2004-02-29 23:24               ` Error-names Björn Persson
2004-03-01 11:29                 ` Error-names Martin Klaiber
2004-03-01 12:48                   ` Error-names Marius Amado Alves
2004-03-02  2:15                     ` Error-names Jeffrey Carter
2004-02-29 20:33             ` Error-names Martin Klaiber
2004-02-29 23:43               ` Error-names tmoran
2004-03-01 11:20                 ` Error-names Martin Klaiber
2004-03-07 15:10                   ` Björn Persson [this message]
2004-03-08  5:42                   ` Error-names Dave Thompson
2004-02-28 20:26         ` Error-names Jacob Sparre Andersen
2004-02-28 18:29 ` Error-names Alexandre E. Kopilovitch
2004-02-29  5:30 ` Error-names David Marceau
2004-02-29 12:17   ` Error-names Martin Klaiber
2004-02-29 19:56     ` Error-names David Marceau
2004-02-29 21:57       ` Error-names Martin Klaiber
2004-03-01 23:20       ` Error-names Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox