[luau] Dazzle me with your C programming prowess
    Jimen Ching 
    jching at flex.com
       
    Mon Apr 22 20:06:47 PDT 2002
    
    
  
On Mon, 22 Apr 2002, Dean Fujioka wrote:
>Thanks for your knowledge jc.
No problem.
>What's funny about this thread to me is that Jeff solved his problem
>before I even posted my response.  I'm glad that you all contribute to
>help a newbie like me learn something.8)
One more tip, before this thread goes into the archives.
One of the problems that new C programmers run into on Unix is with the
math routines in the standard C library.  I.e. if you had a simple C
program like this:
#include <stdio.h>
int main() { printf("Hello world!\n"); return 0; }
You compile it with 'cc helloworld.c', and it would work.  This is because
'cc' automatically added -lc for the standard C library.  But, if you had
this:
#include <stdio.h>
#include <math.h>
int main() { printf("sin(0.7) = %f\n", sin(0.7)); return 0; }
Then the same command will fail.  Why?  Because for some reason, the Unix
gods decided that the standard C library (libc.a) should not have the math
routines in it.  They placed all of the math routines in libm.a.  So the
command line is 'cc helloworld.c -lm'.  Without the -lm, you will get an
error about the 'sin' routine being missing.
Note also.  A few of the math routines are _macros_.  Thus, you have to
include 'math.h' to use _any_ math routines.  I have seen a few questions
asking why math functions don't work.  And the reason is because the
math.h header file was not included.
These are the only two gotcha's that I am aware of.  Everything else
should behave as you would expect.  ;-)
Good luck.
--jc
P.S.  One final tip.  When I got started, I wish someone had pointed me to
the 'C Programming FAQs' written by Steve Summit.  If you read the
comp.lang.c newsgroup, it is posted once a month.  But you can also find
it at:
http://www.eskimo.com/~scs/C-faq/top.html
This document does not teach you to program in C.  But it will help you
avoid many of the pitfalls you might run into.  There is also a version
for C++.  A search for "C++ Programming FAQs" should give you some links.
--
Jimen Ching (WH6BRR)      jching at flex.com     wh6brr at uhm.ampr.org
    
    
More information about the LUAU
mailing list