I wrote a simply program with a 3 D coordinate called point. I am
adding two points, taking their distance etc. gcc compiler is not
identifying the struct. Here is the code. I get bunch of errors. The
main ones are : useless storage class specifier in empty declaration,
'point' undeclared (first use in this function), 'p1' undeclared
(first use in this function) etc. Any help will be appreciated. Thanks
#include <stdio.h>
#include <math.h>
/* create a 3d point struct*/
typedef struct point{
int x,y,z;
};
/* Function declaration*/
float dist(point *, point *);
point add(point *, point *);
void display(point *);
int main(void)
{
point p1,p2,p3;
p1.x=2;p1.y=4;p 1.z=5;
p2.x=5;p1.y=2;p 1.z=6;
printf("\n dist = %f", dist(&p1,&p2));
add(&p1, &p2);
display(&p3);
return;
}
float dist(point *a, point *b)
{
float length=0.0;
length = sqrt( (a->x-b->x)*(a->x-b->x)+ (a->y-b->y)*(a->y-b->y)+
(a->z-b->z)*(a->z-b->z));
return length;
}
point add(point *a, point *b)
{
point temp;
temp.x=a->x + b->x;
temp.y=a->y + b->y;
temp.z=a->z + b->z;
return temp;
}
void display(point *a)
{
printf("\npoint = %d,%d,%d\n",a->x,a->y,a->z);
}
Feb 22 '07
39 3123
In article <11************ **********@h3g2 000cwc.googlegr oups.com>,
santosh <sa*********@gm ail.comwrote:
>This doesn't have anything much to do with gcc. Before gcc was thought of, unix needed -lm to link the maths library, and today the Mac I'm using doesn't need -lm even though its compiler is gcc.
>Are you sure about the latter? I tried a small test program that computes sqrt(2.0) and it didn't require "-lm" because gcc was smart enough to compute the value at compilation time.
>Yes, I made exactly that mistake - I even used sqrt(2.0).
>Try something like sqrt(time(NULL )); it's a silly thing to compute, but it should prevent the compiler from optimizing away the sqrt() call.
But in fact that still works without -lm.
>Then either the compiler has an intrinsic for sqrt or else the latter is present in the same library that contains the non-math standard C functions. Also maybe the environment is secretly supplying the library option?
Foiled again, it's using an inline instruction for sqrt. So this time
I changed it to tgamma(time(0)) , on the assumption that not even the
latest Intel processors have a gamma instruction, and it *still*
doesn't need -lm. Looking at the output of gcc -S and gcc -v, it
appears to be calling a function and linking to a library "-lSystem",
which includes the maths functions.
-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Good evening,
On 2007-02-23, jacob navia <ja***@jacob.re mcomp.frwrote:
Nils Weller a écrit :
>On 2007-02-22, jacob.navia <ja***@jacob.re mcomp.frwrote:
>>> We have often discussed here this msfeature of gcc but they will never change it as it seems.
You cannot remove historical quirks like this without breaking anything, especially if they've been almost universial practice for a couple of decades. I've considered adding -lm by default to my compiler as well, but I figured this would end up doing the users a disservice. Because if you write build scripts for a compiler which does not require you to link that library explicitly, then chances are your project will break if you use it with a different compiler.
Wrong!
They would say
What a bad compiler this one. It needs an explicit -lm switch.
Well, they may not appreciate it, but it would be "for their own
good". ;-)
This isn't a big deal anyway because compilers are already
incompatible in lots of other ways, and I can see where you're
coming from. But myself I would prefer to be warned about such
potential problems, and I can see good reasons for not changing
this particular oddity.
(It would also be nice to get warnings about functions with
dangerously nonportable semantics, such as the signal()
function which is still broken on most System V derivatives,
but that's another story ...)
And the builders of the other compiler would say
Mmmm many users are complaining that the xxx compiler does NOT
need the -lm switch... Should we include it by default?
Yes, this is not a fortunate situation. But you see, there is so
much existing practice that you can't get everyone to change this
without running into new problems. That's all I was saying. If
you get gcc to change, you'd still have to get lots and lots of
other Unix compilers to change, and lots of users to update their
gcc versions.
>It's not just compilers by different vendors that would be affected, but also older versions of a compiler that recently abandoned this requirement. If gcc comes out with a new release that always links with that library by default, as you you suggest, then code developed with that compiler version is more likely not to build with older versions.
So what?
That would impose another implicit (and probably unexpected)
compiler version dependency on your software. The confusion would
be shifted from the developer to the end users, who you shouldn't
expect to have the most up-to-date compiler version available to
compile your stuff.
That would suck.
I have given also much thought to this, and I have developed a
database that is used by the IDE. When it detects a message like
"undefined external reference" it wil look at the database and
propose the libraries to the user...
Good!
I am working with AIX version too. Great system but needs some
more user friendliness.
True. Would also have been nice if it didn't force all-position-
independent code down everyone's throat.
--
Nils R. Weller, Bremen (Germany)
My real email address is ``nils<at>gnuli nux<dot>nl''
.... but I'm not speaking for the Software Libre Foundation!
Richard Tobin wrote:
In article <11************ **********@h3g2 000cwc.googlegr oups.com>,
santosh <sa*********@gm ail.comwrote:
This doesn't have anything much to do with gcc. Before gcc was
thought of, unix needed -lm to link the maths library, and today the
Mac I'm using doesn't need -lm even though its compiler is gcc.
Are you sure about the latter? I tried a small test program that
computes sqrt(2.0) and it didn't require "-lm" because gcc was smart
enough to compute the value at compilation time.
Yes, I made exactly that mistake - I even used sqrt(2.0).
Try something like
sqrt(time(NULL) ); it's a silly thing to compute, but it should prevent
the compiler from optimizing away the sqrt() call.
But in fact that still works without -lm.
Then either the compiler has an intrinsic for sqrt or else the latter
is present in the same library that contains the non-math standard C
functions. Also maybe the environment is secretly supplying the
library option?
Foiled again, it's using an inline instruction for sqrt. So this time
I changed it to tgamma(time(0)) , on the assumption that not even the
latest Intel processors have a gamma instruction, and it *still*
doesn't need -lm. Looking at the output of gcc -S and gcc -v, it
appears to be calling a function and linking to a library "-lSystem",
which includes the maths functions.
Hmm..., curious system, (which one?.) This is a case in point for the
argument to keep this group loosely bound to ISO C.
On Fri, 23 Feb 2007 17:58:11 +0100, in comp.lang.c , jacob navia
<ja***@jacob.re mcomp.frwrote:
>That is why no progress is done in unix... Old bugs are preserved for posterity.
right - that'll be why unix and unix clones are so unsuccessful then.
>The "make" utility needs a tab as the first char in an action line. If you put spaces it will not recognize the line
Apparently you have a /really/ old version of make.
>This BUG has been in all unices since at least 1983,
A bug is when something doesn't behave like its supposed to. Ever used
a fortran compiler? Rry sticking a C character at column seven. Theres
a bug that means it skips that line, apparently.
As it happens, I think the need to put -lm in on some versions of gcc
and some osen is a bit annoying, but its hardly a bug, any more than
having to use vi is a bug, or some versions of SQL not liking iif()
statements. Its just How That Platform Works (tm).
--
Mark McIntyre
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
In article <11************ **********@s48g 2000cws.googleg roups.com>,
santosh <sa*********@gm ail.comwrote:
>Foiled again, it's using an inline instruction for sqrt. So this time I changed it to tgamma(time(0)) , on the assumption that not even the latest Intel processors have a gamma instruction, and it *still* doesn't need -lm. Looking at the output of gcc -S and gcc -v, it appears to be calling a function and linking to a library "-lSystem", which includes the maths functions.
>Hmm..., curious system, (which one?.)
Just a current Mac.
-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
jacob navia <ja***@jacob.re mcomp.frwrites:
Nils Weller a écrit :
>On 2007-02-22, jacob.navia <ja***@jacob.re mcomp.frwrote:
>>We have often discussed here this msfeature of gcc but they will never change it as it seems.
You cannot remove historical quirks like this without breaking anything, especially if they've been almost universial practice for a couple of decades. I've considered adding -lm by default to my compiler as well, but I figured this would end up doing the users a disservice. Because if you write build scripts for a compiler which does not require you to link that library explicitly, then chances are your project will break if you use it with a different compiler.
Wrong!
They would say
What a bad compiler this one. It needs an explicit -lm switch.
And the builders of the other compiler would say
Mmmm many users are complaining that the xxx compiler does NOT
need the -lm switch... Should we include it by default?
Oh, no, I have to type an extra 3 characters!
Most C compilers are not conforming by default; you have to specify
extra options to make then conform to the standard. I agree that the
need for "-lm" is annoying, but I just don't worry about it that much.
>In that case the time you have to deal with this problem is just deferred until a later date. So I think it's best to have to encounter, recognize, and fix this problem as early as possible.
That is why no progress is done in unix... Old bugs are preserved
for posterity. The "make" utility needs a tab as the first char
in an action line. If you put spaces it will not recognize the
line and say:
Missing separator in rules. Stop.
This BUG has been in all unices since at least 1983, when I saw the
first one, and was bitten by this bug.
So you haven't actually been bitten by it since 1983? And what does a
misfeature in "make" have to do with C?
(I don't know whether correcting this might break some existing
Makefiles. Discuss in comp.unix.progr ammer if you're interested.)
>It's not just compilers by different vendors that would be affected, but also older versions of a compiler that recently abandoned this requirement. If gcc comes out with a new release that always links with that library by default, as you you suggest, then code developed with that compiler version is more likely not to build with older versions.
So what?
So code developed with that compiler version is more likely not to
build with older versions.
[...]
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mark McIntyre <ma**********@s pamcop.netwrite s:
On Fri, 23 Feb 2007 17:58:11 +0100, in comp.lang.c , jacob navia
<ja***@jacob.re mcomp.frwrote:
>>That is why no progress is done in unix... Old bugs are preserved for posterity.
right - that'll be why unix and unix clones are so unsuccessful then.
>>The "make" utility needs a tab as the first char in an action line. If you put spaces it will not recognize the line
Apparently you have a /really/ old version of make.
[...]
<OT>
Not necessarily. GNU Make 3.81, the latest version, is less than a
year old. (It at least suggests using a tab rather than 8 spaces.)
</OT>
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
On Thu, 22 Feb 2007 12:35:49 -0600, user923005 wrote
(in article <11************ **********@t69g 2000cwt.googleg roups.com>):
On Feb 22, 10:20 am, "DanielJohn son" <diffuse...@gma il.comwrote:
>>Under most UNIX systems, the math library is seperate and not linked in by default. Add the '-lm' command line switch, (without the quotes), to cc when you compile it.
>>>Is math.sqrt() correct or just sqrt()
>>The latter, with an argument. The former is C++.
Thanks it worked. Do I always need to compile using -lm switch. I was completely unawre if this.
How did you miss this when you read the C-FAQ:
14.3: I'm trying to do some simple trig, and I am #including <math.h>,
but I keep getting "undefined: sin" compilation errors.
A: Make sure you're actually linking with the math library. For
instance, under Unix, you usually need to use the -lm option, at
the *end* of the command line, when compiling/linking. See also
questions 13.25, 13.26, and 14.2.
You will notice that it doesn't actually answer his question.
Specifically, "Do i always" ...
And the answer is no, but if you are using any of the math functions
which require it, then yes obviously for a given program.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw
On Thu, 22 Feb 2007 17:39:04 -0600, Mark McIntyre wrote
(in article <97************ *************** *****@4ax.com>) :
On Thu, 22 Feb 2007 22:12:48 +0100, in comp.lang.c , "jacob.navi a"
<ja***@jacob.re mcomp.frwrote:
>DanielJohnso n a écrit :
>>Thanks it worked. Do I always need to compile using -lm switch. I was completely unawre if this.
We have often discussed here this msfeature of gcc but they will never change it as it seems.
Its not a gcc-ism, please don't mischaracterise it. You're probably
aware that all DOS compilers exhibited this same feature for many
years. I think some early Windows ones even did it (certainly C6 and
Watcom's C compiler did, even when compiling windows-compatible code).
The reason, as far as I recall, is their roots in hardware that didn't
provide floating point support.
You had the option to pick what type of math implementation you wanted
to link against, software fp emulation, 8087, Weitek, 68881/2, etc. I
wonder if lcc-win32 can generate code for a Weitek coprocessor?
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw
Randy Howard wrote:
On Thu, 22 Feb 2007 17:39:04 -0600, Mark McIntyre wrote
><ja***@jacob.r emcomp.frwrote:
>>DanielJohns on a écrit :
Thanks it worked. Do I always need to compile using -lm switch. I was completely unawre if this.
We have often discussed here this msfeature of gcc but they will never change it as it seems.
Its not a gcc-ism, please don't mischaracterise it. You're probably aware that all DOS compilers exhibited this same feature for many years. I think some early Windows ones even did it (certainly C6 and Watcom's C compiler did, even when compiling windows-compatible code). The reason, as far as I recall, is their roots in hardware that didn't provide floating point support.
You had the option to pick what type of math implementation you
wanted to link against, software fp emulation, 8087, Weitek,
68881/2, etc. I wonder if lcc-win32 can generate code for a
Weitek coprocessor?
I doubt it. It won't run on a 486 (at least the debugger portion).
--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steven T. Hatton |
last post by:
The following may strike many of you as just plain silly, but it represents
the kind of delelima I find myself in when trying to make a design
decision. This really is a toy project written for the purpose of learning
to work with C++. It therefore makes some sense for me to give the
situation the amount of consideration presented below. To be quite honest,
I'm amazed at the amount there is to say about such a seemingly simple...
|
by: Robert Rota |
last post by:
Need help figuring out why my program core dumps and if I have the
structures right. If you are interested in helping me I can send you a
copy of the code. The program is supposed to mimic a 3 level
pagetable.
Thank you.
struct _PageTable {
struct _PageTable **PageArray;
unsigned int *FrameArray;
|
by: werasm |
last post by:
Hi all,
What is the difference between:
typedef struct
{
...
} MyS1;
....and...
|
by: Eric |
last post by:
This IS material from a CS class on object oriented programming. It is
NOT my homework.
Consider the following:
struct A {short i; void f () {cout << "A::f()\n";}};
struct B : A {long j; void f () {cout << "B::f()\n";}
void g () {cout << "B::g()\n";}};
{
A* const a = new B; // dangerous (1)
|
by: Zytan |
last post by:
Is it possible, as in C? I don't think it is. Just checking.
Zytan
| |
by: Carramba |
last post by:
Hi!
I want to have a struct representing a table, with int's and float.
But I seem to get only stuckdump.. and not really sure why , hope you
can help!
Thanxk you in advance
#include <stdio.h>
#include <stdlib.h>
|
by: arkmancn |
last post by:
Any comments? thanks.
Jim
|
by: BIll Cunningham |
last post by:
pg 128 of kandr2 speaks of a struct
struct point{
int x;
int y;
};
I understand this but what is it saying about using intialize variables like
such.
|
by: Lew Pitcher |
last post by:
(having trouble getting my reply through - hopefully, third time is a charm)
On November 11, 2008 19:53, in comp.lang.c, BIll Cunningham
(nospam@nspam.invalid) wrote:
Why an int? Because K&R chose to use an int.
Why not a double? Because K&R chose to use an int.
Note the phrase "syntactically analogous". It means that the /syntax/ of
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |