473,378 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Low Level Help Requested.

Thankfully there is a C language group!

Hello!

I am a hobyist who is rediscovering writing C programs on Linux. I
use GCC and I am at a loss as to why the compile fails to find the
following:

Start---

gcc -o gexpr gexpr.c
/tmp/ccbsDbYK.o: In function `term':
/tmp/ccbsDbYK.o(.text+0x172): undefined reference to `fmod'
/tmp/ccbsDbYK.o: In function `expo':
/tmp/ccbsDbYK.o(.text+0x1bf): undefined reference to `pow'
/tmp/ccbsDbYK.o: In function `log2':
/tmp/ccbsDbYK.o(.text+0x1f6): undefined reference to `log'
/tmp/ccbsDbYK.o: In function `factor':
/tmp/ccbsDbYK.o(.text+0x336): undefined reference to `floor'
/tmp/ccbsDbYK.o: In function `main':

End---

ETC....
I'm sure it's me and what I am doing so would you be kind enough to
point out what I am doing wrong in compiling. I use a simple call of
"gcc -o gexpr gexpr.c"

It's been a long time since I wrote programs and I need some help.

Ernst

The Program is as follows

Start---
/* Expression evaluation using plain floating-point arithmetic.
Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software
Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under
the terms of the GNU General Public License as published by the Free
Software
Foundation; either version 2, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more
details.

You should have received a copy of the GNU General Public License
along with
this program; see the file COPYING. If not, write to the Free
Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <string.h>
#include <stdio.h>
#include <setjmp.h>
#include <math.h>

jmp_buf top;

static char *bp, *expr_start_p, *expr_end_p;
static int ch;
static int previous_result_valid_flag;
double previous_result;

double floor (), strtod ();
double term (), expo (), factor (), number ();

#define next skip ()

void
skip ()
{
do
ch = *bp++;
while (ch == ' ' || ch == '\n');
}

void
error ()
{
fprintf (stderr, " ^ syntax error\n");
longjmp (top, 1);
}

double
expr ()
{
double e;
if (ch == '+')
{
next;
e = term ();
}
else if (ch == '-')
{
next;
e = - term ();
}
else
e = term ();
while (ch == '+' || ch == '-')
{ char op;
op = ch;
next;
if (op == '-')
e -= term ();
else
e += term ();
}
return e;
}

double
term ()
{
double t;
t = expo ();
for (;;)
switch (ch)
{
case '*':
next;
t *= expo ();
break;
case '/':
next;
t /= expo ();
break;
case '%':
next;
t = fmod (t, expo ());
break;
default:
return t;
}
}

double
expo ()
{
double e;
e = factor ();
if (ch == '^')
{
next;
e = pow (e, expo ());
}
return e;
}

struct functions
{
char *spelling;
double (* evalfn) ();
};

double
log2 (x)
double x;
{
return log (x) * 1.4426950408889634073599246810019;
}

struct functions fns[] =
{
{"log2", log2},
{"log10", log10},
{"log", log},
{"exp", exp},
{"sqrt", sqrt},
{"floor", floor},
{"ceil", ceil},
{"sin", sin},
{"cos", cos},
{"tan", tan},
{"asin", asin},
{"acos", acos},
{"atan", atan},
{"sinh", sinh},
{"cosh", cosh},
{"tanh", tanh},
{"asinh", asinh},
{"acosh", acosh},
{"atanh", atanh},
{0, 0}
};
double
factor ()
{
double f;
int i;

for (i = 0; fns[i].spelling != 0; i++)
{
char *spelling = fns[i].spelling;
int len = strlen (spelling);
if (strncmp (spelling, bp - 1, len) == 0 && ! isalnum (bp[-1 +
len]))
{
bp += len - 1;
next;
if (ch != '(')
error ();
next;
f = expr ();
if (ch != ')')
error ();
next;
return (fns[i].evalfn) (f);
}
}

if (ch == '(')
{
next;
f = expr ();
if (ch == ')')
next;
else
error ();
}
else
f = number ();
if (ch == '!')
{
unsigned long n;
if (floor (f) != f)
error ();
for (n = f, f = 1; n > 1; n--)
f *= n;
next;
}
return f;
}

double
number ()
{
double n;
char *endp;

if (strncmp ("pi", bp - 1, 2) == 0 && ! isalnum (bp[1]))
{
bp += 2 - 1;
next;
return 3.1415926535897932384626433832795;
}
if (ch == '$')
{
if (! previous_result_valid_flag)
error ();
next;
return previous_result;
}
if (ch != '.' && (ch < '0' || ch > '9'))
error ();
n = strtod (bp - 1, &endp);
if (endp == bp - 1)
error ();
bp = endp;
next;
return n;
}

main (argc, argv)
int argc;
char **argv;
{
int nl_flag = 1;
int hhmm_flag = 0;
int dhhmm_flag = 0;
int round_flag = 0;
int prec = 5;

while (argc >= 2)
{
if (!strcmp (argv[1], "-n"))
{
nl_flag = 0;
argv++;
argc--;
}
else if (!strcmp (argv[1], "-hhmm"))
{
hhmm_flag = 1;
argv++;
argc--;
}
else if (!strcmp (argv[1], "-dhhmm"))
{
dhhmm_flag = 1;
argv++;
argc--;
}
else if (!strcmp (argv[1], "-round"))
{
round_flag = 1;
argv++;
argc--;
}
else if (!strcmp (argv[1], "-prec"))
{
prec = atoi (argv[2]);
argv += 2;
argc -= 2;
}
else if (!strcmp (argv[1], "-help") || !strcmp (argv[1], "-h"))
{
printf ("usage: %s [options] expr [expr ... ]\n", argv[0]);
printf (" options: -n -- suppress newline\n");
printf (" -prec n -- print n digits\n");
printf (" -round -- round to nearesr integer\n");
printf (" -hhmm -- print in base 60 (time
format)\n");
printf (" -dhhmm -- print in base 24,60,60 (time
format)\n");
printf (" -help -- make demons drop from your
nose\n");
exit (0);
}
else
break;
}

if (argc >= 2)
{
int i;
double exp;

for (i = 1; i < argc; i++)
{
expr_start_p = argv[i];
expr_end_p = expr_end_p + strlen (expr_start_p);
bp = expr_start_p;
next;
if (setjmp (top) == 0)
{
int h, m;
exp = expr ();
if (round_flag)
exp = floor (exp + 0.5);
if (hhmm_flag)
{
h = (int) floor (exp);
m = (int) ((exp - floor (exp)) * 60.0 + 0.5);
h += m / 60; m = m % 60;
printf ("%02d:%02d", h, m);
}
else if (dhhmm_flag)
{
double tmp = (exp - floor (exp)) * 24.0;
h = (int) floor (tmp);
m = (int) ((tmp - floor (tmp)) * 60.0 + 0.5);
h += m / 60; m = m % 60;
printf ("%dd %02d:%02d", (int) floor (exp), h, m);
}
else
printf ("%.*g", prec, exp);
if (nl_flag)
puts ("");
previous_result = exp;
previous_result_valid_flag = 1;
}
}
}
else
{
#define BUFSIZE 1024
char buf[BUFSIZE];
double exp;

for (;;)
{
fputs ("eval> ", stdout);
bp = fgets (buf, BUFSIZE, stdin);
if (bp == NULL)
break;
next;
if (setjmp (top) == 0)
{
int h, m;
exp = expr ();
if (round_flag)
exp = floor (exp + 0.5);
if (hhmm_flag)
{
h = (int) floor (exp);
m = (int) ((exp - floor (exp)) * 60.0 + 0.5);
h += m / 60; m = m % 60;
printf ("%02d:%02d", h, m);
}
else if (dhhmm_flag)
{
double tmp = (exp - floor (exp)) * 24.0;
h = (int) floor (tmp);
m = (int) ((tmp - floor (tmp)) * 60.0 + 0.5);
h += m / 60; m = m % 60;
printf ("%dd %02d:%02d", (int) floor (exp), h, m);
}
else
printf ("%.*g", prec, exp);
if (nl_flag)
puts ("");
previous_result = exp;
previous_result_valid_flag = 1;
}
}
}

exit (0);
}

End----
Nov 13 '05 #1
2 2858
nrk
Ernst Berg wrote:
Thankfully there is a C language group!

Hello!

I am a hobyist who is rediscovering writing C programs on Linux. I
use GCC and I am at a loss as to why the compile fails to find the
following:

Start---

gcc -o gexpr gexpr.c
/tmp/ccbsDbYK.o: In function `term':
/tmp/ccbsDbYK.o(.text+0x172): undefined reference to `fmod'
/tmp/ccbsDbYK.o: In function `expo':
/tmp/ccbsDbYK.o(.text+0x1bf): undefined reference to `pow'
/tmp/ccbsDbYK.o: In function `log2':
/tmp/ccbsDbYK.o(.text+0x1f6): undefined reference to `log'
/tmp/ccbsDbYK.o: In function `factor':
/tmp/ccbsDbYK.o(.text+0x336): undefined reference to `floor'
/tmp/ccbsDbYK.o: In function `main':

End---

ETC....
I'm sure it's me and what I am doing so would you be kind enough to
point out what I am doing wrong in compiling. I use a simple call of
"gcc -o gexpr gexpr.c"

It's been a long time since I wrote programs and I need some help.

Ernst

<snip tons of code>

Read the fine FAQ for this group, available at:
http://www.eskimo.com/~scs/C-faq/top.html

In particular, you may find Q14.3 to be helpful here:
http://www.eskimo.com/~scs/C-faq/q14.3.html

-nrk.
Nov 13 '05 #2
On 6 Dec 2003 13:03:52 -0800, in comp.lang.c ,
Er********@sbcglobal.net (Ernst Berg) wrote:
/tmp/ccbsDbYK.o: In function `term':
/tmp/ccbsDbYK.o(.text+0x172): undefined reference to `fmod'


this is a FAQ. 14.3

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Nid | last post by:
How do I do row-level locking on SQL Server? Thanks, Nid
20
by: cylin | last post by:
Dear all, I open a binary file and want to write 0x00040700 to this file. how can I set write buffer? --------------------------------------------------- typedef unsigned char UCHAR; int...
1
by: Frank Lopez | last post by:
In .NET and C#, is there anyway to create a hook for a specific directory or file where my C# .NET software can monitor which static web files are requested by the browser? What I am doing is...
0
by: Rafi Zisman | last post by:
Hi I have small problem. I am using C# . I know how to create owner draw menu, I want to set bigger font in my menu. I have set MenuItem.OwnerDraw = true, and handle the events DrawItem,...
2
by: Amil | last post by:
Hum...am I missing something here. Seems like when I create a new web application in visual studio .net, it will put it at http://localhost/newapp/. This is fine..for now. But, I want to write...
2
by: Nathan | last post by:
I've spent a good part of the afternoon searching Google and the newsgroups for some sort of answer - so I apologize if I'm asking something that has already been asked and answered. I'm using...
3
by: paulh | last post by:
Hello, we are preparing for an upgrade to SQL 2005 and as a result of this I became aware that the compatibility level of one of our databases was set to level 65 (current SQL server is SQL 2000...
6
by: Maxim Veksler | last post by:
Hello, I wish to do some low level network stuff using python. I've googled somewhat and came up with pylibpcap, trouble is I can't compile it on my Ubuntu 6.10 workstation. Can someone please...
25
by: JJ | last post by:
I only want to catch 404 errors at the application level (the rest are will be handled by the customerrors section of the web.config). How do I check for the error code in the Application_Error...
3
by: Ulterior | last post by:
Hi, anyone knows eof() function substitute for linux using open, close and read functions? I am tired of searching in google, sorry
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.