Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Static keyword and const keyword. 1

Status
Not open for further replies.

sbayeta

Programmer
Apr 4, 2003
13
0
0
AR
Hi,
I'm finishing reading The C programming language K&R. I've been programming embedded systems using C for more than a year now. Anyway, I still have some doubts about some stuff. Here goes a couple of questions:

1 - What is the effect of declaring a function to be static ?

2 - What's the practical difference between these prototypes: void func(const char*) and void func(char *) ?

I have several functions taking char* as argument, but I noticed that in the standard library most of the functions taking char pointers are like func(const char*).

Thanks in advance.
 
> 1 - What is the effect of declaring a function to be static ?
It means the name of the function cannot be seen by anything outside the file in which it is declared.
In effect, they become private functions of the source file.

> 2 - What's the practical difference between these prototypes: void func(const char*) and void func(char *
The const means that func() will NOT modify your string.
Just look at the prototype for strcpy()
Unless your function specifically modifies your string, making them const will at least prevent accidental modification of the string should you edit the function later on.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top