Help needed in solving C-errors in Linux (gcc)

From: Dominic Grosleau (dominic_at_localhost.localdomain)
Date: 07/25/03


Date: Thu, 24 Jul 2003 19:14:44 -0400

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

What i really want is for the convert() function in main() to behave correctly to
the way i'm passing its parameter.

I'm guessing i screwed up somewhere in the convertlib.h definition or in
the main.c convert() implementation...

Please help !!!

                                /* main.c */

#include <stdio.h>
#include "convertlib.h"

int main()
{
        int result = 0;

        result = convert(12, "imperial", "inch", "feet");

        printf("\n12 imperial inches = %d feet\n", result);

        return 0;
}

int convert(int unit, const char *sys, const char *initial, const char *final)
{
        int success = 0;

        switch(*sys)
        {
                case 'imperial':
                        if (*initial == 'inch' && *final == 'feet')
                                success = conv_inch2feet(unit);
                default:
                        success = 1;
        };

        return success;
}

                                /*convertlib.h*/
                                

#define FOOT 12 /* # of inches in a foot
int conv_inch2feet(int inch);
int convert(int unit, const char *,const char *,const char *);

                                /*convertlib.c*/
int conv_inch2feet(int inch)
{
        feet = inch / FOOT;

        return feet;
}



Relevant Pages

  • xemacs installation problems
    ... checking for gcc... ... checking whether we are using GNU C... ... checking size of int... ... configure: warning: No OffiX without generic Drag'n'Drop support ...
    (comp.os.linux.misc)
  • Re: gcc bug? Openoffice port impossibel to compile on 4.8
    ... remove this silly "bitten by the Linux bug" and the red-herring of gcc ... struct bar {int a; int b;} dapper; ... The *warning* emitted by gcc when enough analysis is done (e.g. ...
    (freebsd-hackers)
  • Re: How to check if same partition
    ... GCC will bitch when you get this wrong. ... function(int b, int c, int something) ... The gcc version I am using is clever enough not to give this warning ... I covered all cases for argc. ...
    (comp.os.linux.development.apps)
  • Help needed in solving C-errors in Linux (gcc)
    ... i'm trying to make I got the following messages from gcc. ... main.c:22: warning: comparison is always false due to limited range of data type ... int conv_inch2feet; ... int convert(int unit, const char *,const char *,const char *); ...
    (alt.os.linux)
  • Re: static array size: int foo[static 2]
    ... GCC does accept it as legal. ... int read(int fd, const char buf, unsigned count) ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)