|
-
Nov 8th, 2005, 08:01 PM
#1
Thread Starter
Fanatic Member
"private" methods in C
I was just thinking: our professor has told us that there are no private methods in C (which is true), but can't I 'simulate' a private method by putting its declaration in the .c file instead of the .h file?
I mean, this would result in people only being able to access certain methods (unless they imported the .c file as well) but not ones they should keep their hands off.
Right?
Don't pay attention to this signature, it's contradictory.
-
Nov 8th, 2005, 08:09 PM
#2
Addicted Member
Re: "private" methods in C
I always thought there were private methods in C++, but maybe I'm wrong.
-
Nov 8th, 2005, 08:11 PM
#3
Addicted Member
Re: "private" methods in C
Oh, you said C. Sorry. You're probably right about not including it in the header file. That would probably do the trick.
-
Nov 8th, 2005, 11:37 PM
#4
Re: "private" methods in C
Marking a function "static" will make it visible only to the file it's declared in; so if you mark a function in your .c file static, only functions that .c file should be able to reference it.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Nov 8th, 2005, 11:57 PM
#5
Thread Starter
Fanatic Member
Re: "private" methods in C
 Originally Posted by sunburnt
Marking a function "static" will make it visible only to the file it's declared in; so if you mark a function in your .c file static, only functions that .c file should be able to reference it.
Isn't strtok static?
Don't pay attention to this signature, it's contradictory.
-
Nov 9th, 2005, 01:00 AM
#6
Re: "private" methods in C
 Originally Posted by alkatran
Isn't strtok static?
I don't think so, since you must include a .h file (string.h) to use strtok.
Now, it might use static variables inside of it, but a static variable declaration (inside a function) is different from a static function definition and a global static variable.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|