 |
 |
subroutine arguments
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2001
Location: Columbia, MD
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 ]
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|