Thread: pointer dereference problem in sortFunction

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    use
    Code:
        return ((sched_record *) p)->course - ((sched_record *) q)->course;
    Kurt

  2. #2
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    Quote Originally Posted by ZuK View Post
    use
    Code:
        return ((sched_record *) p)->course - ((sched_record *) q)->course;
    Kurt
    Dang! Thank You. I appreciate it. All is good except an undefined reference to 'WinMain@16' in code::blocks in the sortFunction tab and then on the main tab, I get an undefined reference to 'sortFunction.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by csharp100 View Post
    All is good except an undefined reference to 'WinMain@16' in code::blocks in the sortFunction tab and then on the main tab, I get an undefined reference to 'sortFunction.
    Sounds like you have setup a Windows Application project but you have actually written a console application. Also the file sortFunction ( is that the actual name ? it should have a .c extension) has to be added to the project.
    But then I don't know anything about code::blocks
    Kurt
    Last edited by ZuK; 04-19-2012 at 05:08 PM.

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    Actually I just decided to set up a window application project and made new files with the exact same coded as above, with of course the correction to the sortFunction. Now I get a
    Code:
    undefined reference to 'sortFunction'
    I checked the spelling, and I have it defined in my .h file. Wish I can figure this one out. It is pointing to line 26 of my main.c file. I pretty sure this is the way to define the parameters of the qsort function.
    Code:
    qsort(data, MAX_RECORD, sizeof(sched_record), sortFunction);

  5. #5
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    Interesting, I just tried it on our unix system at school and works perfectly fine.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by csharp100 View Post
    Actually I just decided to set up a window application project and made new files with the exact same coded as above, with of course the correction to the sortFunction. Now I get a
    Code:
    undefined reference to 'sortFunction'
    I checked the spelling, and I have it defined in my .h file. Wish I can figure this one out. It is pointing to line 26 of my main.c file. I pretty sure this is the way to define the parameters of the qsort function.
    Code:
    qsort(data, MAX_RECORD, sizeof(sched_record), sortFunction);
    That is a linker error. Verify the spelling and case of the function.
    Make sure you added the C source file containing sortFunction to the CB Project.
    Verify that the files containing the code is really being compiled.
    Verify that the right files are being linked in the right order.

    Turning on Full Compiler Logging should help verify the above items
    FAQ-Compiling (errors) - CodeBlocks

    Tim S.
    Last edited by stahta01; 04-19-2012 at 05:35 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    Here is the compile log:
    Code:
    mingw32-gcc.exe -Wall  -g     -c "C:\Users\Clint Sharp\Documents\C Files\Server1\main.c" -o obj\Debug\main.o
    mingw32-g++.exe  -o bin\Debug\Server1.exe obj\Debug\main.o    
    obj\Debug\main.o: In function `main':
    C:/Users/Clint Sharp/Documents/C Files/Server1/main.c:26: undefined reference to `sortFunction'
    collect2: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 0 seconds)
    1 errors, 0 warnings
    Maybe someone can figure out what the heck is going on.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with dual dereference of a struct pointer
    By dan_paul in forum C Programming
    Replies: 5
    Last Post: 11-12-2011, 09:13 PM
  2. null pointer dereference
    By qwertylurker in forum C Programming
    Replies: 3
    Last Post: 03-14-2011, 12:06 AM
  3. Suspicious dereference of pointer
    By subhashish1213 in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2009, 08:19 AM
  4. Pointer dereference
    By taurus in forum C Programming
    Replies: 1
    Last Post: 11-09-2008, 07:41 AM
  5. Dereference pointer to void pointer to member
    By phil in forum C Programming
    Replies: 5
    Last Post: 04-20-2005, 11:54 AM