Re: Requesting sample code!



Dear barry,

Write 100 times, a function can never be a member of a struct.
Understood!

a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.
a function can never be a member of a struct.

I thought you quit on me a few posts back. No one quits on me, and expects
me to welcome them back!

From now on, when you see one of my posts, don't answer it!
You can view it, but don't answer it.

I expect an appology for the way you have arrogantly answered my previous
posts. I have always respected you and never mistreated you. As everyone
would, I expect the same in return!

If you don't want to appologize, I don't ever want to hear from you again,
ever!
If no one ever thought you courtesy, I will!

You have already posted gobs of code in which a member is a pointer.
Putting a pointer to function in a structure is no different.

No need to use the word "gobs" !

And yeah, I do need a "practical" sample on how to access this type of
member, if you can help arrogance free that is, if not, I ask you to shad up
and get off the post!

========
Mr. Roberto


"Barry Schwarz" wrote:

On Tue, 4 Nov 2008 20:13:00 -0800, Robby
<Robby@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

snip code that doesn't do what is wanted


But I am looking all over for sample code which embeds the functions or
pointers to function in structures. In other words I am looking for sample

In C, you cannot embed a function in a structure.

A pointer to function is a scalar object conceptually no different
than a pointer to int or pointer to char or pointer to struct. You
have already posted gobs of code in which a member is a pointer.
Putting a pointer to function in a structure is no different.

code which would show how to include funtions or pointers to functions as
members of a struct. Very similar ... you know like we do in C++ when we have

Here is a your pointer to function that was defined at block scope in
the code I snipped above:
int (*pf)(int, int);

Here is some code you posted previously in the thread "static array
question?":
typedef struct i{
short v;
}w;

typedef struct z{
int x;
w *xxx;
}f;

Notice that struct z contains two members, the second being a pointer
to struct i. Adding your function pointer after xxx, we get:
typedef struct z{
int x;
w *xxx;
int (*pf)(int, int);
}f;

struct z now contains three members, the third being a pointer to
function.

Given this simplicity, I have to believe I'm missing the real issue in
your question.

methods in our classes. I want to do the same thing with structures. Is this
possible and can someone direct me to some samples or books which illustrate
on how to code this.

The syntax for declaring an object is the same whether the object is a
member of a structure or "stand-alone". Since you know how to declare
an independent pointer to function, you also know how to declare one
that is a member of a function. (You didn't ask but just for
completeness, you access such a member the same way you access any
structure member, using either the . or -> operator as appropriate.)


I would show an example but I don't even know where to start to code this,
but I know it is possible because I have seen something similar to what I
want to do at:

http://bytes.com/forum/thread583012.html

But I would like a full description of how to implement functions and
pointers to functions as members of a struct which is not posted as a
question but rather as a tutorial or book!

Write 100 times, a function can never be a member of a struct.

--
Remove del for email

.



Relevant Pages