Thread: error: ‘y1’ redeclared as different kind of symbol

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    8

    error: ‘y1’ redeclared as different kind of symbol

    hello. I'm learning c, and made a program to calculate the distance between two points.. I got it to compile if my four input variables are xp1, yp1, xp2 and yp2. when I try to compile using x1,y1,x2,y2, I get the error: "error: ‘y1’ redeclared as different kind of symbol"

    why can I use x1, but not y1?

    thanks

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    You've done something wrong.
    Mainframe assembler programmer by trade. C coder when I can.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    can u paste the code ??

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    8

    code for finding distance between two points

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

    Code:
    char line[12];
    float x1,x2,y1,y2;
    float distance;
    main()
    {
            printf("Input X1 Y1: ");
            fgets(line, sizeof(line), stdin);
            sscanf(line, "%f %f", &x1, &y1);
    
            printf("Input X2 Y2: ");
            fgets(line, sizeof(line), stdin);
            sscanf(line, "%f %f", &x2, &y2);
    
            distance = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    
            printf("Distance between points: %f\n", distance);
    
            return (0);
    }
    ******
    there's the code.. thanks to anyone for looking at this..

  5. #5
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    You will need to call gcc with -lm

    Past link on this same issue:
    undefined reference to 'sqrt'

  6. #6
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I pasted your code into my IDE (Xcode on a Mac) and I got the same error.

    I then chose the "Preprocess" option and sure enough, y1 is already used in this context:
    Code:
    extern double y1 ( double );
    So, it sucks that such a "common name" would already be defined. To fix, either pick some new variable names, or, change your variables to local variables by putting the declarations inside main() (they are Global now) to re-scope them.
    Mainframe assembler programmer by trade. C coder when I can.

  7. #7
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    Quote Originally Posted by Dino View Post
    I pasted your code into my IDE (Xcode on a Mac) and I got the same error.

    I then chose the "Preprocess" option and sure enough, y1 is already used in this context:
    Code:
    extern double y1 ( double );
    So, it sucks that such a "common name" would already be defined. To fix, either pick some new variable names, or, change your variables to local variables by putting the declarations inside main() (they are Global now) to re-scope them.


    Oh yes that too! That was strange.

  8. #8
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I know - who would have thunk!
    Mainframe assembler programmer by trade. C coder when I can.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM
  5. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM