Re: is there a way to do this...




sumit1680@xxxxxxxxxxxxxx wrote:
> Novitas wrote:
> > You can achieve the behavior you seek simply by not passing the
> > variable by "reference" but by value -- that is remove the preceding &
> > from the argument. The subroutine will have to have its prototype
> > changed from int * to int.
> >
> > If there is more to your question, you will need to explain further.
>
> Agreed .... but i keep my original approach and yet want to do so....
> in a way what i want is to somehow increment pc (program counter ) to
> skip the execution of line i=6 .agreed this introduces architecture
> dependency ,yet , implementation wise how to achive the same...

In that case, I'd recommend something like the following:

void main()
{
int i=5;
if (change(&i))
i=6;
printf("%d",i); //it should print 23 instead of 6
}

int change( int *i)
{
*i=23;

//write some code here so that output of printf in main will be 23
not 6
return 0; /// Note, -- in the general case there would be
conditional
/// logic deciding on a 1 or 0 as the return value.
}

You could also use longjmp to cause return to a different place in the
program, but it's a lot messier and tends to excessively couple the
internals of the subroutine to the main routine.

The bottom line is that one has to live within the limits of what the
language
provides with a few prescribed exceptions (none of which are in
evidence
given the information you provided so I won't go into that)

It is necessary for the change routine to communicate in some manner
whether or not the statement that follows will or will not be executed.
Giving it a
boolean return value is the most straightforward way I can think of.

.



Relevant Pages

  • Re: Way to autogenerate C/C++ Headers?
    ... end subroutine odessa_segment_initialize ... #ifdef FTN_ALLCAPS ... int STDCALL odessa_segment_create_ ( ...
    (comp.lang.fortran)
  • Re: Problem in declaration
    ... The way subroutine in which this statement, INTEGER*4 JR*2, ... an array of size INT. ... It seems that I need to have a reference book on MS FORTRAN. ...
    (comp.lang.fortran)
  • Re: recursion
    ... Why are you using globals? ... argument the subroutine needs explicitly, and to keep most variables local ... int powered; ... In the example you posted, however, powered must run twice, because the ...
    (comp.lang.c)
  • Re: Form k = i + j and test for overflow.
    ... One would not expect to call a subroutine without ... In C operations such as addition of types smaller than int are done ... after converting to int. ... I don't believe that Fortran does the same thing. ...
    (comp.lang.fortran)
  • Re: What if black holes are just a glitch in the matrix?
    ... Computer programs are deterministic... ... char data; ... int f{ ... of course converted into a deterministic machine during execution, ...
    (sci.physics)