SPONSORS:






User Tag List

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Jul 2002
    Location
    Redwood City, CA, US
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing variables by reference allowed?

    I am trying to do the equivalent in 4Test for the following C/C++ sample:

    BOOL SomeFunction (int& VariableToChange)
    {
    // do something to get the value we want to change
    // now modify the referenced value
    VariableToChange = 100; // or whatever

    // now return the actual function return
    if (VariableToChange != 0)
    {
    return TRUE;
    }
    return FALSE;
    }

    int main() {
    int VariableToChange;

    SomeFunction(VariableToChange);

    printf("new value = %d \n",
    VariableToChange);

    return 0;
    }

    So I want to pass a reference to a defined variable and have the function itself modify the value and then be able to use that modified value from the calling function. 4Test has something called the @ "reference operator" but it doesn't *appear* to me to be the same thing as the & in C/C++. I am pretty new to 4Test so any help would be appreciated.

    ------------------

  2. #2
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Passing variables by reference allowed?

    Easy - use the keyword 'out' (or the keyword 'inout') when specifying the required input variables in your function declaration. For example:
    Use the pass-mode keyword 'out' if you need to pass an argument by reference; use the pass-mode keyword 'in' if you need to pass an argument by value. The default is 'in' (i.e. if you don't specify a pass-mode then it passes by value).
    'inout' is in practice exactly the same thing as 'out', I don't understand why they are specified as different, but the language reference claims they are different in some sense.
    Disclaimer: I know how the pass-mode operators work for simple variable types; when it comes to passing objects (windows) into a function, I can't say I'm an expert. To be honest, I've never needed done sufficiently complicated OO stuff in silktest to need to worry about it.

    ------------------

  3. #3
    Junior Member
    Join Date
    Jul 2002
    Location
    Redwood City, CA, US
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Passing variables by reference allowed?

    Perfect! Thanks very much.

    ------------------

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 02:10 AM.

Copyright BetaSoft Inc.