Poster | Thread |
falemagn
| |
Re: Begining C Posted on 6-Oct-2004 0:23:19
| | [ #21 ] |
|
|
|
Super Member |
Joined: 24-Nov-2003 Posts: 1126
From: Italy | | |
|
| @Rogue
Quote:
The problem here is that pi is a double, but you are using %f, which is a float. Varargs functions don't have any means to correctly "guess" the type before calling the function.
You should add "-Wall" to the command line when compiling, it will notify you of such problems.
|
The fact he's using a double with %f is perfectly legit. Floats get promoted to double's when passing them to vararg functions, and thus printf's %f modifier works on double's, not floats. Where did you take your information from?
Here's a reference
_________________ “It is well enough that people of the nation do not understand our banking and monetary system, for if they did, I believe there would be a revolution before tomorrow morning.” ~~ Henry Ford |
|
Status: Offline |
|
|
Intuitioned
| |
Re: Beginning C Posted on 6-Oct-2004 0:27:49
| | [ #22 ] |
|
|
|
Super Member |
Joined: 27-Oct-2003 Posts: 1340
From: Unknown | | |
|
| *edit* the phantom double post bug strikes again!!! Last edited by Intuitioned on 06-Oct-2004 at 12:35 AM.
_________________
|
|
Status: Offline |
|
|
Intuitioned
| |
Re: Beginning C Posted on 6-Oct-2004 0:32:10
| | [ #23 ] |
|
|
|
Super Member |
Joined: 27-Oct-2003 Posts: 1340
From: Unknown | | |
|
| Hang in there Swoop. Once you get round these twatish compiler annoyances you be making excellent progress.
OT,
Anybody know whats wrong with this,
#define INVALID_DATA -1 ... int width = 1000, height = 1000; double *pdData = new double[width * height]; memset(pdData, INVALID_DATA, sizeof(double) * width * height);
(Doh!) _________________
|
|
Status: Offline |
|
|
Xenic
| |
Re: Beginning C Posted on 6-Oct-2004 4:12:01
| | [ #24 ] |
|
|
|
Super Member |
Joined: 2-Feb-2004 Posts: 1246
From: Pennsylvania, USA | | |
|
| I just compiled the program with GCC 2.95.3 on an A4000 (OS 3.9) exactly as it appeared in your message:
#include
int main() { double pi = 3.141526536; printf ("The value of pi is approximatley %f\n", pi ); return 0; }
When I ran the program it printed the following line in the shell window:
The value of pi is approximatley 3.141527
If I use (float)pi I get 3.141526.
Not much help I know, but at least you know it should work.
By the way, do programs compiled with GCC 2.95.3 from the OS4 SDK need the ixemul.library like the 68k version I'm using.
Your program needs -lm on the command line if I compile it without ixemul (using Libnix instead).
gcc test.c -noixemul -lm -o testprog -Wall
_________________ X1000 with 2GB memory & OS4.1FE
|
|
Status: Offline |
|
|
nicomen
| |
Re: Begining C Posted on 6-Oct-2004 6:04:24
| | [ #25 ] |
|
|
|
Cult Member |
Joined: 5-Nov-2003 Posts: 539
From: Trondheim, Norway | | |
|
| @Swoop
Do you have the latest clib2 from http://sourceforge.net/projects/clib2 ? _________________ Nicolas Mendoza |
|
Status: Offline |
|
|
Swoop
| |
Re: Begining C Posted on 6-Oct-2004 7:16:24
| | [ #26 ] |
|
|
|
Elite Member |
Joined: 20-Jun-2003 Posts: 2163
From: Long Riston, East Yorkshire | | |
|
| @nicomen
I have just downloaded it, and will try that when I get Home.
Also I seem to remember there were some gcc patches on OS4Depot, I`m going to get them as well and see if that corrects the problem.
_________________ Peter Swallow. A1XEG3-800 [IBM 750FX PowerPC], running OS4.1FE, using ac97 onboard sound.
"There are 10 types of people in the world: those who understand binary, and those who don't." |
|
Status: Offline |
|
|
riksweeney
| |
Re: Begining C Posted on 6-Oct-2004 9:29:15
| | [ #27 ] |
|
|
|
Member |
Joined: 20-Jan-2004 Posts: 50
From: Unknown | | |
|
| @Swoop
The only time I've ever encountered the problem you described was when I didn't link against the maths lib.
i.e.
gcc pi.c -o pi
would result in your current problem. Changing it to
gcc pi.c -o pi -lm
corrected this issue. |
|
Status: Offline |
|
|
pjhutch
| |
Re: Beginning C Posted on 6-Oct-2004 11:42:46
| | [ #28 ] |
|
|
|
Regular Member |
Joined: 13-May-2003 Posts: 194
From: W Yorkshire, UK | | |
|
| @Swoop
For more Amiga OS type programming, try my new tutorial at:
http://www.pcguru.plus.com/programming.html
The C tutorial with (when done), will cover: Libraries, Screens, Windows, Menus, Gadgets, Sprites/Bobs, Line Graphics, Backdrops, Requesters, Fonts, I/O with joystick/mouse, Sound and Arexx.
I have just finished first 3 and started on Menus.
Last edited by L8-X on 06-Oct-2004 at 05:02 PM.
_________________ Peter J Hutchison http://www.pjhutchison.org/ |
|
Status: Offline |
|
|
ssolie
| |
Re: Beginning C Posted on 6-Oct-2004 16:41:12
| | [ #29 ] |
|
|
|
Elite Member |
Joined: 10-Mar-2003 Posts: 2755
From: Alberta, Canada | | |
|
| @Xenic Quote:
By the way, do programs compiled with GCC 2.95.3 from the OS4 SDK need the ixemul.library like the 68k version I'm using. |
OS4 currently doesn't support ixemul.library and likely never will (at least in its entirety). The situation is much more like the old libnix days. You are correct that you need to include -lm in order to use any floating point math.
By default, you get the clib2 C library on OS4. You can choose to use the newlib C library by adding -newlib to the GCC compiler options. The big advantage of newlib being that it is a shared library so it is better for small footprint applications._________________ ExecSG Team Lead |
|
Status: Offline |
|
|
Swoop
| |
Re: Begining C Posted on 6-Oct-2004 17:21:48
| | [ #30 ] |
|
|
|
Elite Member |
Joined: 20-Jun-2003 Posts: 2163
From: Long Riston, East Yorkshire | | |
|
| @ssolie & riksweeney
I`ve just run it again with the following:- Quote:
gcc -o firstvar firstvar.c -lm |
and I get the result Quote:
The value of pi is approximatley 3.141527 |
which is what I expected the first time.
I had tried the -lm flag before, and it had no effect, all I did this time was to follow the same format as ssolie suggested, and made sure the -lm option was at the end, and it worked. I was under the impression that the order of flags/options was relatively flexible with gcc.
Thanks everyone for your help, now for the third example.
@pjhutch
I found an introduction to gcc in pdf format, on google, which I have posted on its own thread. which might be a useful link on your site. I will try your tutorials over the weekend.
_________________ Peter Swallow. A1XEG3-800 [IBM 750FX PowerPC], running OS4.1FE, using ac97 onboard sound.
"There are 10 types of people in the world: those who understand binary, and those who don't." |
|
Status: Offline |
|
|