Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C Programming Language

Changing the execution path of methods at runtime


Hi All,

Can i change the execution path of methods in my process at runtime?

e.g

a()->b()->c()->d()->e()

Now, i want execution to be altered at runtime as -

a()->b()->myfun1()->myfun2()->myfun3()... ->e()

Can this be done without changing the actual source file, may be by
adding a new module at runtime?

Thanks

--pradeep

In article <1180449520.473891.53@q19g2000prn.googlegroups.com>,

blufox  <2500.prad@gmail.com> wrote:
>Can i change the execution path of methods in my process at runtime?

Not in C, because C does not have methods.

>e.g
>a()->b()->c()->d()->e()
>Now, i want execution to be altered at runtime as -
>a()->b()->myfun1()->myfun2()->myfun3()... ->e()
>Can this be done without changing the actual source file, may be by
>adding a new module at runtime?

C does not have modules either. Furthermore, C does not offer any
method of activating new code at runtime.

Some operating systems provide mechanisms for dynamically loadable
objects. In the Windows world, these are usually called 'dll';
in the Unix world, these are usually called 'dso' but the
Unix operating system calls usually begin with dlopen() .
--
   Okay, buzzwords only. Two syllables, tops.  -- Laurie Anderson

On May 29, 7:43 pm, rober@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
> In article <1180449520.473891.53@q19g2000prn.googlegroups.com>,

> blufox  <2500.prad@gmail.com> wrote:
> >Can i change the execution path of methods in my process at runtime?

> Not in C, because C does not have methods.

Right. Apologies i meant kernel functions in linux which are usually
called methods.

> >e.g
> >a()->b()->c()->d()->e()
> >Now, i want execution to be altered at runtime as -
> >a()->b()->myfun1()->myfun2()->myfun3()... ->e()
> >Can this be done without changing the actual source file, may be by
> >adding a new module at runtime?

> C does not have modules either. Furthermore, C does not offer any
> method of activating new code at runtime.

> Some operating systems provide mechanisms for dynamically loadable
> objects. In the Windows world, these are usually called 'dll';
> in the Unix world, these are usually called 'dso' but the
> Unix operating system calls usually begin with dlopen() .

Right, and i mean a Linux kernel module here.
Essentially it is C(with loads of GCCism) i guess.

So, is it possible using modules in unix/linux then. i must ask?

Thanks for the reply
--pradeep

Hi

a()->b()->c()->d()->e()

means (in C):

call function a(), that returns some pointer to a
structure that has a field called "b". This field is a function
pointer. Call that, and that will return some structure with
a field "c". That field is a function pointer...

etc

Note that the type of the return of a() is known at compile
time. The compiler has then calculated at which offset the "b"
pointer is, and generates code to access that pointer at that
offset. You can't change that. You can only change the value
in the field "b", in the structure returned by a().

If a returns the same structure but with a function pointer to
"myfun", the generated code will work the same, but you will
end calling another function, not the one that you were calling

This requires a modification at compile time to a() or to b(), etc.

Somehow those functions will need to figure out when they should put
a certain function pointer in field "b" or not.

But all this looks far too complicated.

WHAT are you trying to do?

Explain that first.

jacob

On May 29, 8:01 pm, jacob navia <j@jacob.remcomp.fr> wrote:

Oops i messed it up i must admit. :-(
No it is not pointer dereferencing literally here.
Just to illustrate the flow of program here, i used arrows "->" .

What I intend to do?

I want to invoke my function without changing the actual source code
at runtime.

Is this somehow possible on a Linux system?

Thanks

--pradeep

On May 29, 4:07 pm, blufox <2500.prad@gmail.com> wrote:

It's just about possible using portable C, but only if you design the
source file to make it possible. For instance:

/* whichfunc.c */
extern void c(void);
extern void myfun1(void);
void (*func)()=c; /* =myfun1; */

/* prog.c */
extern void (*func)();

void a(void)
{
  b();

}

void b(void)
{
  (*func)(); /* the key line */

}

/* ... whatever ... */

Then you can link both files together using whatever implementation-
specific method your implementation provides (if you're on Linux,
you're quite possibly using gcc, in which case you specify both files
on the command line or probably use a makefile if it's a complex
project). Changing func will change the path of execution b takes.

Of course, modifying the source code is nearly always going to be
easier (the only advantage of doing it like this is that you can
change the flow pattern at runtime if you want to, by assigning to
func).

In the general case, in which you haven't deliberately written the
source code in this unusual form, you can't substitute a call to one
function with another using what's available in standard C89/C99.
--
ais523

blufox <2500.prad@gmail.com> writes:
> On May 29, 7:43 pm, rober@ibd.nrc-cnrc.gc.ca (Walter Roberson)
> wrote:
>> In article <1180449520.473891.53@q19g2000prn.googlegroups.com>,

>> blufox  <2500.prad@gmail.com> wrote:
>> >Can i change the execution path of methods in my process at runtime?

>> Not in C, because C does not have methods.
> Right. Apologies i meant kernel functions in linux which are usually
> called methods.

They are?  That's news to me.

In any case, you should ask on a Linux-specific newsgroup.

--
Keith Thompson (The_Other_Keith) k@mib.org  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center             <*>  <http://users.sdsc.edu/~kst>
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

On May 30, 3:00 am, Keith Thompson <k@mib.org> wrote:
> blufox <2500.prad@gmail.com> writes:
> > On May 29, 7:43 pm, rober@ibd.nrc-cnrc.gc.ca (Walter Roberson)
> > wrote:
> >> In article <1180449520.473891.53@q19g2000prn.googlegroups.com>,

> >> blufox  <2500.prad@gmail.com> wrote:
> >> >Can i change the execution path of methods in my process at runtime?

> >> Not in C, because C does not have methods.
> > Right. Apologies i meant kernel functions in linux which are usually
> > called methods.

> They are?  That's news to me.

Yes they are called methods in the kernel AFAIK.
May be i am misunderstanding it.

> In any case, you should ask on a Linux-specific newsgroup.

Tried that, didn't get satisfying answers so resorted to clc.
I 'll give another try though.

Thank you
--psr

On May 29, 8:30 pm, ais523 <ais@bham.ac.uk> wrote:

This is fruitful.
I ll look into this and see if i can get something concrete from this
hint.

Thanks a ton for the help.

--psr

blufox wrote:
> ais523 <ais@bham.ac.uk> wrote:

... snip about 100 lines ...

>> Of course, modifying the source code is nearly always going to be
>> easier (the only advantage of doing it like this is that you can
>> change the flow pattern at runtime if you want to, by assigning to
>> func).

>> In the general case, in which you haven't deliberately written the
>> source code in this unusual form, you can't substitute a call to one
>> function with another using what's available in standard C89/C99.

> This is fruitful.  I ll look into this and see if i can get something
> concrete from this hint.

Please snip irrelevant data from the quoted portion of your
replies.  The links below (in my sig) may be helpful.

--
Some useful links on quoting:
 <http://www.xs4all.nl/%7ewijnands/nnq/nquote.html>
 <http://www.complang.tuwien.ac.at/anton/mail-news-errors.html>
 <http://www.netmeister.org/news/learn2quote2.html>
 <http://www.star-one.org.uk/computer/format.htm>

--
Posted via a free Usenet account from http://www.teranews.com

On 29 May 2007 20:42:00 -0700, in comp.lang.c , blufox

<2500.prad@gmail.com> wrote:
>On May 30, 3:00 am, Keith Thompson <k@mib.org> wrote:
>> blufox <2500.prad@gmail.com> writes:
>> > Right. Apologies i meant kernel functions in linux which are usually
>> > called methods.
>> They are?  That's news to me.
>Yes they are called methods in the kernel AFAIK.

I've never heard anything called a method in C or C++. Some other
languages such as VB and the ilk have methods.

>May be i am misunderstanding it.

Its possible...

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
 Therefore, if you write the code as cleverly as possible, you are,
 by definition, not smart enough to debug it."
--Brian Kernighan

In article <5mvr53570pi03qamr05lmtfa5au3ck5@4ax.com>,
Mark McIntyre  <markmcint@spamcop.net> wrote:

>On 29 May 2007 20:42:00 -0700, in comp.lang.c , blufox
><2500.prad@gmail.com> wrote:

>>On May 30, 3:00 am, Keith Thompson <k@mib.org> wrote:
>>> blufox <2500.prad@gmail.com> writes:

>>> > Right. Apologies i meant kernel functions in linux which are usually
>>> > called methods.

>>> They are?  That's news to me.

>>Yes they are called methods in the kernel AFAIK.

>I've never heard anything called a method in C or C++. Some other
>languages such as VB and the ilk have methods.

Of course you have (heard someone refer to C++ as having methods).
That part of your statement (that "I've never heard...") is plain and
simply a lie.

The more substantive question is whether or not C++ has methods.  Pretty
clearly, it does (although of course this is all OT here), but I would
imagine that you or one of your buddies will come up with some bit of
sophistry to explain why it doesn't.

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc