Error with cc sunstudio compiler - Unix

This is a discussion on Error with cc sunstudio compiler - Unix ; I compiled that program under turbo C without any problems but with sunstudi I found those errors: "pnt02ma1.c", line 37: warning: implicit function declaration: system "pnt02ma1.c", line 58: operands must have arithmetic type: op "*" "pnt02ma1.c", line 58: assignment type ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Error with cc sunstudio compiler

  1. Error with cc sunstudio compiler

    I compiled that program under turbo C without any problems but with
    sunstudi I found those errors:

    "pnt02ma1.c", line 37: warning: implicit function declaration: system
    "pnt02ma1.c", line 58: operands must have arithmetic type: op "*"
    "pnt02ma1.c", line 58: assignment type mismatch:
    pointer to float "=" double
    "pnt02ma1.c", line 59: operands must have arithmetic type: op "/"
    "pnt02ma1.c", line 60: operands have incompatible types:
    pointer to float "-" double
    "pnt02ma1.c", line 61: operands must have arithmetic type: op "/"
    "pnt02ma1.c", line 62: operands have incompatible types:
    pointer to float "-" double
    "pnt02ma1.c", line 62: warning: improper pointer/integer combination:
    op "="
    cc: acomp failed for pnt02ma1.c


    /*-----------------------pnt02ma1.c---------------------
    Given those formulas
    ---inch = cm / 2.45
    ---inch =(meter * 100)/2.45


    ---feet = 12 inch
    ---yard = 3 feet
    ---yard = 36 inch
    ---inch = 1/12 feet
    ---inch = 1/36 yard

    ---yard > feet > inch

    convert given meter value to (yards , feet , and inches)

    1-convert meter to the smallest unit = (inches).
    2-obtain yards (biggest required value).
    3-obtain the remainder inches after getting yards. m=m%36
    4-obtain feet (second biggest required value).
    5-obtain the remainder inches after getting feets.i=m%12
    ---------------------------------------*/


    #include "stdio.h"

    void input(float *);
    void conversion(float *,int *,int *,int *);
    void print_reults(float *,int *,int *,int *);
    char another(void);

    int main ()
    {
    float meter;
    int yards,feet,inches;
    do {
    system("cls");
    input(&meter);
    conversion(&meter,&yards,&feet,&inches);
    } while (another()=='y');
    return 0;
    }


    void input(float *m)
    {
    printf("\nEnter size in meter :");
    scanf("%f",m);
    printf("\nYou have entered size in meter %.4f\n",*m);

    }


    void conversion(m,y,f,i)
    float *m;
    int *y,*f,*i;
    {
    m=m*100.0/2.54;
    *y=m/36.0;
    m=m-(*y)*36.0;
    *f=m/12.0;
    *i=m-(*f)*12.0;
    printf("\n %.2f meter is = %4d yards %4d feet %4d inches
    ",*m,*y,*f,*i);
    }


    char another()
    {
    char a;
    printf("\n\n Do ou want to another procees (y/n)");
    scanf("\n%c",&a);
    return (a);
    }

  2. Re: Error with cc sunstudio compiler

    happytoday wrote:
    > I compiled that program under turbo C without any problems but with
    > sunstudi I found those errors:
    >
    > "pnt02ma1.c", line 37: warning: implicit function declaration: system
    > "pnt02ma1.c", line 58: operands must have arithmetic type: op "*"
    > "pnt02ma1.c", line 58: assignment type mismatch:
    > pointer to float "=" double
    > "pnt02ma1.c", line 59: operands must have arithmetic type: op "/"
    > "pnt02ma1.c", line 60: operands have incompatible types:
    > pointer to float "-" double
    > "pnt02ma1.c", line 61: operands must have arithmetic type: op "/"
    > "pnt02ma1.c", line 62: operands have incompatible types:
    > pointer to float "-" double
    > "pnt02ma1.c", line 62: warning: improper pointer/integer combination:
    > op "="
    > cc: acomp failed for pnt02ma1.c
    >

    So? These are all valid diagnostics, study them and fix the code.

    >
    > void conversion(m,y,f,i)
    > float *m;
    > int *y,*f,*i;
    > {


    Why are you using obsolete K&R functions?

    --
    Ian Collins.

  3. Re: Error with cc sunstudio compiler

    happytoday wrote:
    > I compiled that program under turbo C without any problems but with
    > sunstudi I found those errors:
    >
    > "pnt02ma1.c", line 58: operands must have arithmetic type: op "*"


    This is the offending line

    m=m*100.0/2.54;

    where 'm' is declared as 'float*'. Not surprisingly, the compiler
    complains. I don't know how you managed to compile it in turbo C and,
    frankly, I don't believe it is possible.

    --
    Best regards,
    Andrey Tarasevich

  4. Re: Error with cc sunstudio compiler

    happytoday wrote:
    > I compiled that program under turbo C without any problems


    Then Turbo C must be even crapier than I thought.

    > but with sunstudi I found those errors:
    >
    > "pnt02ma1.c", line 37: warning: implicit function declaration: system


    You should include to get the prototype for system(), even
    if the implicit one (under C90) happens to be okay.

    > "pnt02ma1.c", line 58: operands must have arithmetic type: op "*"
    > "pnt02ma1.c", line 58: assignment type mismatch:
    > pointer to float "=" double
    > "pnt02ma1.c", line 59: operands must have arithmetic type: op "/"
    > "pnt02ma1.c", line 60: operands have incompatible types:
    > pointer to float "-" double
    > "pnt02ma1.c", line 61: operands must have arithmetic type: op "/"
    > "pnt02ma1.c", line 62: operands have incompatible types:
    > pointer to float "-" double
    > "pnt02ma1.c", line 62: warning: improper pointer/integer combination:
    > op "="
    > cc: acomp failed for pnt02ma1.c
    >
    >


    > #include "stdio.h"


    #include

    >
    > void input(float *);
    > void conversion(float *,int *,int *,int *);
    > void print_reults(float *,int *,int *,int *);
    > char another(void);
    >
    > int main ()
    > {
    > float meter;
    > int yards,feet,inches;
    > do {
    > system("cls");


    This is unlikely to work under *nix.


    > void conversion(m,y,f,i)
    > float *m;
    > int *y,*f,*i;


    Don't use old K&R style function declarations.

    void conversion(float *m, int *y, int *f, int *i)

    > {
    > m=m*100.0/2.54;


    What is the type of m? What does it mean to multiply a
    pointer by a double?



    --
    Peter

  5. Re: Error with cc sunstudio compiler

    In comp.unix.programmer happytoday wrote:
    > I compiled that program under turbo C without any problems but with
    > sunstudi I found those errors:


    > "pnt02ma1.c", line 37: warning: implicit function declaration: system
    > "pnt02ma1.c", line 58: operands must have arithmetic type: op "*"
    > "pnt02ma1.c", line 58: assignment type mismatch:
    > pointer to float "=" double
    > "pnt02ma1.c", line 59: operands must have arithmetic type: op "/"
    > "pnt02ma1.c", line 60: operands have incompatible types:
    > pointer to float "-" double
    > "pnt02ma1.c", line 61: operands must have arithmetic type: op "/"
    > "pnt02ma1.c", line 62: operands have incompatible types:
    > pointer to float "-" double
    > "pnt02ma1.c", line 62: warning: improper pointer/integer combination:
    > op "="
    > cc: acomp failed for pnt02ma1.c


    I somehow doubt that the program when compiled with Turbo C
    did anything reasonable. Most compilers are a bit more picky,
    which has the advantage that you get some idea what you did
    wrong instead of ending up with a program that does something
    strange.

    > #include "stdio.h"


    > void input(float *);
    > void conversion(float *,int *,int *,int *);
    > void print_reults(float *,int *,int *,int *);
    > char another(void);


    > int main ()


    Better make that

    int main( void )

    > {
    > float meter;
    > int yards,feet,inches;
    > do {
    > system("cls");


    system(3) is declared in which you didn't include.
    You may also find that 'cls' isn't a command that the shell
    knows about, SunOS (or whatever your machine is running) is
    not DOS...

    > input(&meter);
    > conversion(&meter,&yards,&feet,&inches);
    > } while (another()=='y');
    > return 0;
    > }


    > void input(float *m)
    > {
    > printf("\nEnter size in meter :");
    > scanf("%f",m);


    Using scanf() for getting input from a user is rather difficult
    to get right. Just try what happens if you enter something else
    than a number here...

    > printf("\nYou have entered size in meter %.4f\n",*m);


    > }


    > void conversion(m,y,f,i)
    > float *m;
    > int *y,*f,*i;


    Why are you mixing the very-old style of specifying function para-
    meters with the "new" (but already 18 years old) way? Better use

    void conversion( float *m, int *y, int *f, int *i )

    > {
    > m=m*100.0/2.54;


    I guess you meant

    *m = *m * 100.0 / 2.54;

    > *y=m/36.0;


    And here:

    *y = *m / 36.0;

    And the same in the next three lines. BTW, why do you pass pointers
    to the function if you don't have to? It doesn't look as if you are
    interested in changes to these values in the caller.

    > m=m-(*y)*36.0;
    > *f=m/12.0;
    > *i=m-(*f)*12.0;
    > printf("\n %.2f meter is = %4d yards %4d feet %4d inches",*m,*y,*f,*i);
    > }


    > char another()


    Also here it's better use

    char another( void )

    > {
    > char a;
    > printf("\n\n Do ou want to another procees (y/n)");
    > scanf("\n%c",&a);
    > return (a);
    > }

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ jt@toerring.de
    \__________________________ http://toerring.de

  6. Re: Error with cc sunstudio compiler

    happytoday wrote:
    > I compiled that program under turbo C


    Get rid of turbo C since it's outdated. The C language has changed
    considerably since then. You will not learn correct C by reading turbo
    C tutorials. That means programs you write are not valid C these days.

+ Reply to Thread