#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep 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. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    I think it's just a simple misspelling. I think you meant abs
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    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.

    Comments on this post

    • salem agrees : well said

IMN logo majestic logo threadwatch logo seochat tools logo