Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:472)
OrbWorks Community Forum • View topic - Prototypes

Prototypes

Discuss PocketC for Palm OS (including Desktop Edition)

Postby DaveEverett on Sat Jan 06, 2001 12:46 pm

Can someone please show me what a function prototype should look like?

Thanks.
DaveEverett
 
Posts: 8
Joined: Sat Jan 06, 2001 12:44 pm

Postby wolfgang on Sat Jan 06, 2001 8:59 pm

Hello,

the prototype looks exactly like a function header, except that it is terminated with a ";" and no function body follows. Example:

Function:

my_func (int my_var)
{
// do something
}

The prototype for this function would be

my_func (int my_var);

In regular C you can omit the parameters variable names (I don't know if PocketC allows this, too):

my_func (int);

Wolfgang
Composing music on the PocketPC! - http://www.pdamusician.com
wolfgang
 
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA

Postby tclarke on Sun Jan 07, 2001 3:04 pm

Why would I need to use these in PocketC?

What purpose do they serve in PocketC?

Tom
Tom
tclarke
 
Posts: 42
Joined: Wed Dec 13, 2000 11:03 am
Location: USA

Postby DaveEverett on Sun Jan 07, 2001 10:38 pm

Thanks for the info.

I need prototypes to avoid a chicken and egg problem during compilation. Apparently I can't call a sub until it's been compiled.

Creating the prototypes fixed the problem.
DaveEverett
 
Posts: 8
Joined: Sat Jan 06, 2001 12:44 pm

Postby tclarke on Mon Jan 08, 2001 12:59 am

Just to make sure I understand, the purpose of a prototype is to enable me to put the 'real' functions in any order, as long as the prototypes are at the beginning of the program. Right?
Is there any other reason to use prototypes?

Tom
Tom
tclarke
 
Posts: 42
Joined: Wed Dec 13, 2000 11:03 am
Location: USA

Postby slmiller on Mon Jan 08, 2001 6:12 pm

That's pretty much all they do. The reason they are needed is to avoid problems with functions calling other functions during compilation. The problem could be avoided by copying/pasting the functions around to put them in the right order, but it is obviously simpler to just rearrange your single-line prototypes.

Duct tape is The Force. It has a light side, a dark side, and it holds the world together.
"To beer. The cause of, and solution to, all of life's problems" - Homer Simpson
slmiller
 
Posts: 63
Joined: Mon Jan 08, 2001 6:09 pm
Location: USA

Postby wolfgang on Mon Jan 08, 2001 10:54 pm

There is one other reason (actually the one why they are used most of the time): You can put all the prototypes (without any code) into a header file (.h) and have the actual functions in a separate c file (.c, or .pc for PocketC). In that way one can separate nicely definition and implementation, very useful for libraries etc. There might not even be the source code for the .c file available, only the compiled object file to be linked to the full program (that's only possible in regular C, not in PocketC). You can still use the functions in your code by including the header files with the prototypes.

Wolfgang
Composing music on the PocketPC! - http://www.pdamusician.com
wolfgang
 
Posts: 281
Joined: Tue Dec 12, 2000 4:22 am
Location: USA

Postby tclarke on Tue Jan 09, 2001 1:44 am

Thank you, all. Now it makes sense...

Tom
Tom
tclarke
 
Posts: 42
Joined: Wed Dec 13, 2000 11:03 am
Location: USA


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 3 guests