• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling C Function without declaring prototype

 
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys, I am in the middle of learning C. I thought that if we wanted to call C function, we had to declared a prototype first. Look at the code



It still works even though I commented the function declaration. I use NetBeans 6.5.1 as an IDE and WINGW compiler. Thanks !!!

Jeffry Kristianto Yanuar SCJP, SCJA, SCJD

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My C is a bit rusty... You don't have to declare the function first, but if you don't, the C compiler will assume the function returns an int (even if the real function, defined later, doesn't). It's a bit strange, but this is how C works. It's a good idea to always declare functions before you call them.

Doesn't the compiler give you a warning if you do this? Most modern C compilers will give a warning if you do this.
 
Jeffry Kristianto Yanuar
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surprisingly, when Compiling using NetBeans 6.8 RC1, I get the error message. The most possibility is NetBeans 6.5.1 and NetBeans 6.8 RC1 invoke gcc command using different parameter.

By The way, what books do you use when learning C ?

Jeffry Kristianto Yanuar SCJP, SCJA, SCJD
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you can change the settings that NetBeans uses to call gcc. I haven't programmed in C for a long time, so I don't know how to do that, but it's probably not hard to find in the preferences of NetBeans. When calling gcc from the command line, it's usually a good idea to use -Wall (which means: turn on all warnings), for example:

gcc -Wall hello.c -o hello

I'm sorry but I don't have a good book recommendation for C - I learned C a long time ago, on the Amiga when I was 16 or so.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic