Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > subroutine arguments

subroutine arguments
Thread Tools
Dedicated MacNNer
Join Date: Apr 2001
Location: Columbia, MD
Status: Offline
Reply With Quote
Nov 5, 2001, 08:50 PM
 
This is based on a call from one of the examples in one of Apple's documents:
...
OneCommandHandler((WindowRef) userData );
...
pascal void OneCommandHandler( WindowRef window)

.....

I don't understand what is going on here...It seems there are an unequal number of arguments in the call than in the subroutine itself. I'm trying to add one more argument to the subroutine, but if I put it before or after "WindowRef window", I get errors during compile.

How do I add an extra parameter.

thanks
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Boulder, CO, USA
Status: Offline
Reply With Quote
Nov 5, 2001, 09:40 PM
 
Originally posted by rogerkylin:
<STRONG>This is based on a call from one of the examples in one of Apple's documents:
...
OneCommandHandler((WindowRef) userData );
...
pascal void OneCommandHandler( WindowRef window)

.....

I don't understand what is going on here...It seems there are an unequal number of arguments in the call than in the subroutine itself. I'm trying to add one more argument to the subroutine, but if I put it before or after "WindowRef window", I get errors during compile.

How do I add an extra parameter.

thanks</STRONG>
The call (the first line you have there) is casting the variable userData to the WindowRef type. It's passing one argument.

To add another parameter to OneCommandHandler, you'll have to find the prototype of the function, if there is one, add the extra arg there, and then add the extra arg to the actual function definition, and finally make sure that every call to it -- wherever it's used -- passes two arguments.

That's assuming OneCommandHandler is all your code and that you don't have to make it match a function pointer type required by some OS API. In other words, do you ever have to pass the name OneCommandHandler to any function you didn't write?
     
Senior User
Join Date: Feb 2001
Location: Rochester, uk
Status: Offline
Reply With Quote
Nov 6, 2001, 05:43 AM
 
the code <BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>(type) value</font>[/code] is for casting the value into a different type. So an arguments list might look like:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>...arg, (short) <font color = blue>5</font>, arg...</font>[/code]

What i don't personally understand is that pascal keyword.
All words are lies. Including these ones.
     
Forum Regular
Join Date: Oct 2001
Location: Sweden
Status: Offline
Reply With Quote
Nov 6, 2001, 06:51 AM
 
Originally posted by sadie:
<STRONG>What i don't personally understand is that pascal keyword.</STRONG>
I think that is a directive to the processor to pass the arguments (and store a potential return value) according to the conventions used for the pascal language. Different languages use the stack and registers in different ways. Since the mac toolbox APIs were originally written in Pascal, when those APIs were to be made available through C, this keyword had to be used. At least this is my understanding of the subject. You shoudn't have to care about it, it won't affect how you write your code, it's only meant for the compiler.
     
Forum Regular
Join Date: Oct 2001
Location: Sweden
Status: Offline
Reply With Quote
Nov 6, 2001, 06:55 AM
 
I should add one thing: if the API requires you to provide a callback of some sort, then you might be forced to use the pascal keyword in definitions of functions you write yourself. In those cases just copy the prototype for that callback from the documentation, complete with any keywords.
     
Dedicated MacNNer
Join Date: Apr 2001
Location: Columbia, MD
Status: Offline
Reply With Quote
Nov 6, 2001, 07:14 AM
 
I had tried the following two variations to pass a simple character and neither worked (I also updated the prototype).


OneCommandHandler((WindowRef) userData,"1" );
...
pascal void OneCommandHandler( WindowRef window,char nmbr)

and

OneCommandHandler("1",(WindowRef) userData );
...
pascal void OneCommandHandler(char nmbr, WindowRef window)

but the compiler complained (I'm at work on my stupid PC now so I can't remember or reproduce the error).
     
Forum Regular
Join Date: Oct 2001
Location: Sweden
Status: Offline
Reply With Quote
Nov 6, 2001, 07:25 AM
 
Originally posted by rogerkylin:
OneCommandHandler("1",(WindowRef) userData );
...
pascal void OneCommandHandler(char nmbr, WindowRef window)
if the argument is of type char you should use '1', not "1"

[ 11-06-2001: Message edited by: tobli ]
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:59 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2