Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
April 1st, 2013, 06:30 PM
 ps3
Registered User

Join Date: Oct 2012
Posts: 2
Time spent in forums: 56 m 29 sec
Reputation Power: 0
Udefined reference to abd??

I am getting a compilation error as-
undefined reference to abd
snippet--
Code:
```#include<stdio.h>
#include<math.h>

int main()
{
int t;
long long int xs,ys,xd,yd,temp;
double n;
scanf("%d",&t);
while(t--)
{
scanf("%lld %lld %lld %lld",&xs,&ys,&xd,&yd);
xs=abs(xs); ys=abs(ys); xd=abs(xd); yd=abs(yd);
if((xs-ys)*(xd-yd)<0) { temp=xs; xs=ys; ys=temp; }
if(abs(xs-ys) > abd(xd-yd)) printf("NO\n");
else if(xs>=ys)
{
n=log(yd-xs+1)/log(2)-1;
if((xd==ys && (yd-xs)%ys==0)  || (n>=0 && n==(int)n))
printf("YES\n");
}
else if(xs<ys)
{
n=log(yd-xs+1)/log(2)-1;
if(n>=0 && n==(int)n && yd<=ys)
{
n=log(xd-ys+1)/log(2)-1;
if((xd-ys)%xs==0 || (n>=0 && n==(int)n))
printf("YES\n");
}
}
else
printf("NO\n");
}
return 0;
}```

#2
April 1st, 2013, 07:53 PM
 bullet
Java Junkie

Join Date: Feb 2004
Location: Mobile, Alabama
Posts: 3,967
Time spent in forums: 1 Month 2 Weeks 1 Day 7 h 31 m 49 sec
Reputation Power: 1283
I think it's just a simple misspelling. I think you meant abs

#3
April 1st, 2013, 08:10 PM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,863
Time spent in forums: 3 Months 1 Day 7 h 5 m 13 sec
Reputation Power: 2199
And did it also tell you "line 16" (or whatever line that is in your code)? That information would have been helpful to us.

Here's the offending line:
if(abs(xs-ys) > abd(xd-yd)) printf("NO\n");
I assume that you mistyped and had intended that to be abs().

As I said, the error message should have taken you directly to that line. I used my editor's search function to find abd, which you could have done as well.

If your question is actually what that message means, it means that you're using an identifier that you hadn't defined. C requires us to declare an identifier (eg, variable name, typedef'd data type, function name) before we use it, so if you use an identifier before or without declaring it, you will get that error.

OK, that wasn't quite completely true. C has legacy behavior in which it will complain, but then create that undefined identifier with a default declaration, which is int. When it's a function, then it assumes that the undefined function returns int and takes one int argument, but then when it encounters the function it complains a second time about that function having been "redefined". Watch out for this legacy behavior.

And in case you think that C is being unreasonable about insisting that you declare everything first, consider what life was like in FORTRAN and BASIC, where all you had to do to create a new variable was to use it. So when you mistyped a variable name, it just started using that new spelling as another variable, thus creating one of the most frustrating kind of bugs imaginable, especially since when you read your own code, you don't see what is actually there but rather what you "know" is there, so it's almost impossible to find that misspelling bug.

There was a famous story of such a bug in the program that calculated the launching of a satellite. Reaching back more then 3 decades, there was a DO loop (analogous to a C for-statement) like this:
DO 9 I=1, 10
Only, the programmer mistyped a period for that comma, changing that loop to a simple assignment statment:
DO9I=1.10 (FORTRAN allowed spaces in identifier names)
So instead of initializing ten variables, it only initialized one that was never used. As the story goes, because of that single mistyped punctuation mark the satellite ended up on the ocean floor. Being required to declare all your variables before being allowed to use them is a good thing.
salem agrees: well said

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Udefined reference to abd??