Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Incomprehensible error... any ideas?


  • Please log in to reply
5 replies to this topic

#1 Aereshaa

Aereshaa

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 638 posts

Posted 10 February 2010 - 01:10 PM

inline void foo(){}
int main(){foo();}
That seemingly innocent code gives the following linker error:
$gcc -std=c99 -Wall -Wextra -pedantic inlinetest.c
/tmp/cc4A48Yu.o: In function `main':
inlinetest.c:(.text+0x12): undefined reference to `foo'
collect2: ld returned 1 exit status

  • 0
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#2 outsid3r

outsid3r

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 494 posts

Posted 10 February 2010 - 02:09 PM

Edit:
I didn't check that you were coding in C. I never tried to inline a function in C, so i don't know why that happens.
  • 0

#3 dcs

dcs

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 730 posts

Posted 10 February 2010 - 02:19 PM

Dunno.

D:\projects\misc\c>gcc -std=c99 -Wall -Wextra -pedantic main.c

D:\projects\misc\c>gcc --version
gcc (GCC) 3.4.5 (mingw-vista special)

Clean out the project directory, etc.?
  • 0

#4 bobdark

bobdark

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 155 posts

Posted 10 February 2010 - 02:20 PM

I don't think inline functions are part of C. As far as I remember were supposed to replace (at least partially) macro's and were something new of C++ that did not appear in C.
Plus , you don't return an integer in main.
  • 0

#5 outsid3r

outsid3r

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 494 posts

Posted 10 February 2010 - 02:21 PM

So, after all it was like i was saying at my first post? it acts like C++. Inline functions are like macros, they expand then called, so you can't produce object code from them.
  • 0

#6 outsid3r

outsid3r

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 494 posts

Posted 10 February 2010 - 02:24 PM

I don't think inline functions are part of C. As far as I remember were supposed to replace (at least partially) macro's and were something new of C++ that did not appear in C.
Plus , you don't return an integer in main.


No, inline functions are part of C99, and some compilers supported it as an extension before C99.
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download