Re: Help needed in solving C-errors in Linux (gcc)
From: Josef Möllers (josef.moellers_at_fujitsu-siemens.com)
Date: 07/25/03
- Next message: Randy Howard: "Re: Which language will use?"
- Previous message: Josef Möllers: "Re: Watchdog"
- In reply to: Dominic Grosleau: "Help needed in solving C-errors in Linux (gcc)"
- Next in thread: Josef Möllers: "Re: Help needed in solving C-errors in Linux (gcc)"
- Reply: Josef Möllers: "Re: Help needed in solving C-errors in Linux (gcc)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 25 Jul 2003 08:51:54 +0200
Dominic Grosleau wrote:
>
> When i tried to compile this test driver for an actual conversion library
> i'm trying to make I got the following messages from gcc.
>
> /*problems reported*/
>
> gcc convertlib.c main.c -ansi -pedantic
>
> main.c:21:22: warning: character constant too long
> main.c:22:41: warning: multi-character character constant
> main.c: In function `convert':
> main.c:22: warning: comparison is always false due to limited range of data type
> main.c:22:61: warning: multi-character character constant
> main.c:22: warning: comparison is always false due to limited range of data type
> case 'imperial':
First of all, this is what the error message says it is: a
"multi-character character constant". A string (that's what you want,
but not what you can use here, see below) is delimited by double quotes:
"imperial".
However, you can't use a string in a switch statement. The switch
statement only works on "constant integer values".
You'll need to use nested if/else if's with strcmp:
if (strcmp(sys, "imperial") == 0)
{
if (strcmp(initial, "inch") == 0 && strcmp(final, "feet") == 0)
success = conv_inch2feet(unit);
}
else
success = 1;
Thus said, I'd like to give some advice (this smells like homework ...):
use table-lookup:
struct {
char *sys, *initial, *final;
int (*convfunc)(int);
} convtable[] = {
{ "imperial", "inch", "feet", &conv_inch2feet },
{ NULL, NULL, NULL, NULL }
};
-- Josef Möllers (Pinguinpfleger bei FSC) If failure had no penalty success would not be a prize -- T. Pratchett
- Next message: Randy Howard: "Re: Which language will use?"
- Previous message: Josef Möllers: "Re: Watchdog"
- In reply to: Dominic Grosleau: "Help needed in solving C-errors in Linux (gcc)"
- Next in thread: Josef Möllers: "Re: Help needed in solving C-errors in Linux (gcc)"
- Reply: Josef Möllers: "Re: Help needed in solving C-errors in Linux (gcc)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|