PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > Error with cc sunstudio compiler
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Error with cc sunstudio compiler

Réponse
 
LinkBack Outils de la discussion
Vieux 15/04/2008, 23h36   #1
happytoday
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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);
}
  Réponse avec citation
Vieux 15/04/2008, 23h51   #2
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Vieux 15/04/2008, 23h55   #3
Andrey Tarasevich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 15/04/2008, 23h58   #4
Peter Nilsson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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 <stdlib.h> 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
>
>

<snip>
> #include "stdio.h"


#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");


This is unlikely to work under *nix.

<snip>
> 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?

<snip>

--
Peter
  Réponse avec citation
Vieux 16/04/2008, 00h13   #5
Jens Thoms Toerring
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Error with cc sunstudio compiler

In comp.unix.programmer happytoday <ehabaziz2001@gmail.com> 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 <stdlib.h> 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
  Réponse avec citation
Vieux 16/04/2008, 00h31   #6
Nikos Chantziaras
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h26.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,41762 seconds with 14 queries