What is a function prototype in C

preview_player
Показать описание
---
What is a function prototype in C // Function prototypes often catch new C and C++ programmers by surprise. This video is an attempt to clear things up.

***

Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.

About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.

More about me and what I do:

To Support the Channel:
+ like, subscribe, spread the word

Рекомендации по теме
Комментарии
Автор

Without them, foo couldn’t call bar and that would be a sad sad day

JustinCromer
Автор

the way someone explained it to me that helps remember to put prototypes before using is; to treat it like declaring a variable. you can't use a variable before declaring it. i know there is differences, but i feel it is a good frame of reference to a new programmer or at least a new C / C++ programmer.

samplesandtests
Автор

That was a clear explanation. Thanks, Dr.

This is similar to hoisting in JavaScript .

Hoisting is JavaScript's default behavior of moving all declarations to the top of the current scope (to the top of the current script or the current function)

Barakatic
Автор

These quick little C basics videos are really useful. Thanks

benjaminrich
Автор

Hi, congrats for your videos. For this one, in order to be more educational/demonstrative, you could have : a) Showed the _printf_ prototype in header file; b) wrote foo() and bar() into two separate source code files; c) created your own header file containing foo() and bar() prototype. This would have been more _in real life_ C project demo. Thanks anyway, Peace!

philpeko
Автор

You are a very good teacher - It's a great thing you decided to post your videos!

marcelnowakowski
Автор

I am a person that wrote some or more C code :) .
This Youtube Channel, is making C very easy to learn, if you do not know .
C actually is a easy or very easy programming language.

mihailteodorescu
Автор

Header files are full of prototypes its really useful to put all the prototypes into a header and just include that header when working with multiple c/c++ files

joshuangerng
Автор

Got an idea for your next vid, c++ templates vs preprocessor templates, preprocessor being where you make a bunch of defines your template expects (in place of <...> of the c++ templates) and use #include to use your template (in other words the template is an entire file on it's own) which in turn undefines those defines once it's done with them (unless it's expected that you will use the defines still after said template's inclusion)

**Edit:** As an aside it's also possible to replicate the inheritance of members like c++ classes do by putting the members in their own file then including that file at the top of the struct you're defining, damn sight clearer as to what goes where too. With that technique on top of the preprocessor templates and the callback typedefs, there's no actual value to c++ besides syntactic sugar and overloading

zxuiji
Автор

This is also called "forward declaration".

sledgex
Автор

Is because the compiler needs to know how much stack space it needs to grow when calling a function (in addition to any automatic variables it may have).

Akn
Автор

Your C programming language points are very useful and great.
As you know, writing fast and accurate numerical calculation programs is always the concern of numerical calculation programmers.
I think figuring out how to implement math functions in the C compiler is a safe and standard way to develop your own mathematical library.
Because the compiler was written by very professional people. But my problem is that I don't understand its written literature.
For example, I could not find how a function like SQRT is implemented. If possible, please advise. Thankful

VasDaniel
Автор

These prototypes, you can move them to a .h file (header) and include that?

Which then allows you to move the implementations to another .c file (C? source? code?) and compile that separately? (then link the compilations as last step?)

If yes then I think I'm beginning to understand this flow a bit more...

re.liable
Автор

Hi, Jacob, greetings from San Francisco. I have found that explaining function prototypes to newbies is an excellent gateway to a discussion explaining HOW C passes parameters to the called function on the stack, and how the return parameter is returned ON the stack, along with an attendant et discussion of the concept of FRAMES. Are you going there to?

greg
Автор

I am new to C, so I have to ask:
They seem to be completely unnecessary and not make any sense. Why not just declare the function as it is at the top of the source file? Then you have the functionality, the return type, the arguments and the compiler compiles.

anyname
Автор

You should make a video on _Generic. Show how to use it and maybe even do a simple array example. Something similar to C++'s std::vector.

anon_y_mousse
Автор

Please make a video about _Generic and it's usage

avimalka
Автор

It’s also called a forward declaration.

jamesbush
Автор

GCC gave me this warning today: "warning: a function definition without a prototype is deprecated in all versions of C and is not supported in C2x"

leegibson
Автор

I think you glossed a little too much on why it's needed.

If you wanted, it's easy enough to straight #include all your code. But I think? for libraries like you said it is not a choice at all, you must use the linker after compilation, the code is not baked into your executable in a kind of outdated desire to save space repeating the same libs again and again on your filesystem.

CaptainWumbo