delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/30/01:42:39

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: function arguments aliases?
Date: Sat, 29 Mar 1997 01:48:44 -0800
Organization: Two pounds of chaos and a pinch of salt
Lines: 73
Message-ID: <333CE57C.2F5@cs.com>
References: <333AF42A DOT 4E59 AT post DOT comstar DOT ru> <5hfilt$4m6 AT sky DOT inp DOT nsk DOT su>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp215.cs.com
Mime-Version: 1.0
CC: Dim Zegebart <zager AT post DOT comstar DOT ru>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Michael Bukin wrote:
> 
> >void foo(int x,int y)
> >{
> >// may I use here not x y names but somthing like arg1 and arg2 ?
> >// For example :
> > putpixel(arg1,arg2); //instead of putpixel(x,y)
> >}

I don't quite understand the point of this... after all, the names you
call variables by don't matter beans except for being soomething that
you can understand.  You don't have to call function parameters by the
same names as the values you pass to that function, nor do the names
have to match the names in the prototype.  If you want 'arg1' and
'arg2', just define your function as "void foo( int arg1, int arg2 )".

If you want to access the function's arguments globally for some strange
reason, then you are out of luck.  The arguments are stored on the
stack, which means they cease to exist as soon as the function returns. 
There's nothing stopping you from doing something like this, though:

void foo( int x, int y )
{
    static int arg1, arg2;
    arg1 = x;
    arg2 = y;
    putpixel( arg1, arg2 );
    return;
}

Each time this function is called, the values of the static variables
arg1 and arg2 will be changed to equal the parameters passed to the
function.  I have no idea if this is what you want, though.

> >(I'm using DJGPP v2.2)

Umm... there ain't no such thing.  You mean 2.01, right?  Or did I
somehow miss a half-dozen releases?  ;)

> For C, you can try the following:
> --------------------
> void
> foo (int a1, int a2)
> {
> #define a3 a1
> #define a4 a2
>   fprintf (stderr, "%d, %d, %d, %d\n", a1, a2, a3, a4);
> #undef a3
> #undef a4
> }
> --------------------
> But I don't recommend it. Just forger #undef a3 and in the rest of file
> a3 will be replaced with a1. The best you can get is 'undefined variable a1',
> the worst, assignment to a3 will assign to a1, which probably is not what you want.

Yeah, but in the rest of the file, 'a1' and 'a2' do not exist.  So you
will get a huge pile of errors about "Undefined symbol 'a1'", etc.  If
you want to make a1 and a2 into global variables, well then, use global
variables!  Don't mess around with all this wierd stuff.

It would help if the original poster (Dim Zegebart) would say exactly
what it is that he is trying to _do_ in his program.  Then maybe we can
figure out the correct way to implement it.  :)

-- 
John M. Aldrich, aka Fighteer I <fighteer AT cs DOT com>

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s+:- a-->? c++>$ U@>++$ p>+ L>++ E>++ W++ N++ o+>++ K? w(---)
O- M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+(++) tv+() b+++ DI++ D++ G>++
e(*)>++++ h!() !r !y+()
------END GEEK CODE BLOCK------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019