Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Calling C Function without declaring prototype

 
Ranch Hand
Posts: 759
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic