Jump to content
Sign in to follow this  

'C' VAR Parameters

Recommended Posts

I recently tried the P2C part of the program, and it's very nice.  The Pascal compiler supports 'VAR' parameters -- sending in a variable as a parameter, changing it in the subroutine, and getting the CHANGED version back.  It looks very simple in the assembly output.


Is there some way to do this with 'C'?  Normally, I'd pass an 'int *' var in and change it.  That is clearly not supported. C++ and Java do this with 'references' -- pass an "int & MyVar", and any changes to it are returned to the calling function.  Is this supported?


Thanks, AllanL5.

Share this post

Link to post
Share on other sites

Okay, I have a VERY non-portable 'C2C' compiler-based work-around.  It consists of two Macro's 'GETVAL' and 'GET_IVAL'.  These are:


// Having called a routine, get the modified parm into 'MyVal'.

// GetVal for CHAR quantities,  GET_IVAL for INT quantities.

// Expected: MyVal is __

//           ParmNum is ParamNN_

#define GETVAL( MyVal, ParmNum ) \

 asm { movfw ParmNum } asm { movwf MyVal }


#define GET_IVAL( MyVal, ParmNum) \

            asm {movfw ParmNum} \

asm {movwf MyVal} \

asm {movfw ParmNum + 1} \

asm {movwf MyVal + 1}


// And a use example:

     increment(i);  GETVAL (_i_main, param00_increment);


// And another -- 'L' and 'M' are int:


       GET_IVAL (_L_main, param00_inc3);

       GET_IVAL (_M_main, param01_inc3);

Share this post

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...