Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   polymorphism in C (http://www.velocityreviews.com/forums/t955530-polymorphism-in-c.html)

Jack 12-16-2012 12:29 AM

polymorphism in C
 
I found a code to do polymorphism in C (taken from a book):

struct Class {
size_t size;
void * (* ctor) (void * self, va_list * app);
void * (* dtor) (void * self);
void * (* clone) (const void * self);
int (* differ) (const void * self, const void * b);
};

The book says the first argument of those functions of the above struct has to be a pointer to "self". Why?

Thanks.

Jack

Eric Sosman 12-16-2012 12:52 AM

Re: polymorphism in C
 
On 12/15/2012 7:29 PM, Jack wrote:
> I found a code to do polymorphism in C (taken from a book):
>
> struct Class {
> size_t size;
> void * (* ctor) (void * self, va_list * app);
> void * (* dtor) (void * self);
> void * (* clone) (const void * self);
> int (* differ) (const void * self, const void * b);
> };
>
> The book says the first argument of those functions of the above struct has to be a pointer to "self". Why?


If the function -- (*differ)(), say -- wants to operate on the
struct instance, it needs a way to find that struct.

If that's not clear, try implementing an augmented class:

struct Class {
size_t size;
...
void (*print)(FILE *stream); // no "self"
};

Your mission, should you choose to accept it, is to write a
function that `print' could reasonably point to. Note that
this function has no obvious way to discover which struct it
is supposed to print ...

--
Eric Sosman
esosman@comcast-dot-net.invalid

JimB 12-16-2012 07:40 AM

Re: polymorphism in C
 
Eric Sosman wrote:
> On 12/15/2012 7:29 PM, Jack wrote:
>> I found a code to do polymorphism in C (taken from a book):
>>
>> struct Class {
>> size_t size;
>> void * (* ctor) (void * self, va_list * app);
>> void * (* dtor) (void * self);
>> void * (* clone) (const void * self);
>> int (* differ) (const void * self, const void * b);
>> };
>>
>> The book says the first argument of those functions of the above
>> struct has to be a pointer to "self". Why?

>
> If the function -- (*differ)(), say -- wants to operate on the
> struct instance, it needs a way to find that struct.
>
> If that's not clear, try implementing an augmented class:
>
> struct Class {
> size_t size;
> ...
> void (*print)(FILE *stream); // no "self"
> };
>
> Your mission, should you choose to accept it, is to write a
> function that `print' could reasonably point to. Note that
> this function has no obvious way to discover which struct it
> is supposed to print ...


Your imposition, should you choose to acknowledge it... well it is (was? are
we all grown up now Mz. "court-appointed" "psychologist"? That means ...
what does it mean? Am I "crazy"? No, THEY need more than that (can you say
gestapo?). What about the gun? Will I accept it as my savior and bow to it?
The record shows that I am "a flag-burner".

I feel this is an M.O.: all horrors that preceded this time.

Rape is rape. Fear is a valid reason not to "die for your country". Their is
no "country". There is rape though. Enlist the immature (yes, you lil bitch
wannabe authoritarian of deciding peoples's fate: **** you bitch), in the
name of "Freedom!", of course. Rape is rape.

Rape is "easy". No one dies, there is no war. Is war easier than rape? I
say, "you" are "the president of the united ****ing states", say, and what
do you say to christians on their holiday? Pfft! Hello: their sufferring is
a bit less than donald trump and bill gates but you will come to your
salvation.. when you DIE [for your country].

For the stupid: there is no "country". There is no "nation". There is no
FLAG.. You though, at every juncture, from birth on, are charged with
"carrying the flag".

Rape is rape.

a big problem.



Shao Miller 12-16-2012 08:39 AM

Off-Topic: JimB Posts
 
On 12/16/2012 02:40, JimB wrote:
>
> a big problem.
>


The regulars will most probably never forgive me, but...

What is it that compels you to type this (above) and the "Why Jacob
Navia hates C" post? I believe that you recognize what you've typed as
being off-topic for people interested in the C programming language. So
if that's true, why post these? Because you can? Do you gain
something? Are you drunk? Are you bored? Are you hopeful that a
reader will have some poetic appreciation of these? Do you just want
some feedback, like mine? What sorts of comments could you throw my
way? Are you a fledgling artificial intelligence with limited means of
interacting with the world? Is there something you desire that one or
more comp.lang.c readers could grant you?

I'm trying to understand your motives. You presumably sit down at your
computer and open up your news-reader, then fetch the latest comp.lang.c
material, then read at least some of the postings, then... What? You
think. You decide to post something. Why? Perhaps you carefully
choose what type. If so, what sorts of thoughts go into those choices?

Do you ever consider anyone else's perspective? What would it be like
to be someone else, reading a post like one of these two that you've
typed? How might other people feel about them? How might other people
react? Is there a particular way that you want other people to react?
Do you take comfort in the knowledge that someone has read what you've
typed (like this)? Do you enjoy observing a certain amount of output
from yourself result in a larger response from another (like this)?

What is driving you? Can you be honest about it in a response? Or is
the answer private? Is there a sequence of magic words that could
result in your cessation of posting off-topic messages? How about
this?: Please stop posting off-topic messages.

JimB 12-16-2012 11:25 AM

Re: Off-Topic: JimB Posts
 
Shao Miller wrote:
> On 12/16/2012 02:40, JimB wrote:
>>
>> a big problem.
>>

>
> The regulars will most probably never forgive me, but...
>
> What is it that compels you to type this (above) and the "Why Jacob
> Navia hates C" post? I believe that you recognize what you've typed
> as being off-topic for people interested in the C programming
> language. So if that's true, why post these? Because you can?



That is a valid quetioon (not that other questiins are not valid)

>Do
> you gain something?


wouldn't it be that I am missing someone?
> Are you drunk?

Yeah.
> Are you bored?

Wasn't the drunken thiing the prob?

> Are you hopeful
> that a reader will have some poetic appreciation of these?

No I am not gifted with music (I just get to listen to it and hate
you))

> just want some feedback, like mine? What sorts of comments could you
> throw my way? Are you a fledgling artificial intelligence with
> limited means of interacting with the world?


Yes..For sure.

> Is there something you
> desire that one or more comp.lang.c readers could grant you?
>


No. I''m way ok, and if you wanna go a few rounds with me well, I wil
**** you up.]]

Don't call me out in defense of your .......... I jest, I don't , I mean I
hateL USA go to hell.



JimB 12-16-2012 11:58 AM

Re: Off-Topic: JimB Posts
 
Yes you are right on pint.
what is you point?

Shao



Shao Miller 12-16-2012 08:48 PM

Re: Off-Topic: JimB Posts
 
On 12/16/2012 06:25, JimB wrote:
>
> No. I''m way ok, and if you wanna go a few rounds with me well, I wil
> **** you up.]]
>


Sometimes I don't bother trying to be unpredictable, either. ;)

On 12/16/2012 06:58, JimB wrote:
> Yes you are right on pint.
> what is you point?


I might have two points, though neither of them would be particularly
attractive or repulsive:

1. I don't understand your motives for posting off-topic messages, but I
might like to.

2. I'd enjoy comp.lang.c more without such off-topic messages.

Good fortune to you.

Keith Thompson 12-16-2012 10:33 PM

Re: Off-Topic: JimB Posts
 
Shao Miller <sha0.miller@gmail.com> writes:
> On 12/16/2012 02:40, JimB wrote:
>>
>> a big problem.
>>

>
> The regulars will most probably never forgive me, but...
>
> What is it that compels you to type this (above) and the "Why Jacob
> Navia hates C" post?

[snip]

Shao, by all means feel free to waste your time asking about the
motivations of an obvious troll. But please don't waste everyone
else's time by doing it here.

(JimB: *plonk*)

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Shao Miller 12-16-2012 11:39 PM

Re: Off-Topic: JimB Posts
 
On 12/16/2012 17:33, Keith Thompson wrote:
> Shao Miller <sha0.miller@gmail.com> writes:
>> On 12/16/2012 02:40, JimB wrote:
>>>
>>> a big problem.
>>>

>>
>> The regulars will most probably never forgive me, but...
>>
>> What is it that compels you to type this (above) and the "Why Jacob
>> Navia hates C" post?

> [snip]
>
> Shao, by all means feel free to waste your time asking about the
> motivations of an obvious troll. But please don't waste everyone
> else's time by doing it here.
>


That is why the subject clearly includes "off-topic" in it.

If you can provide me with the e-mail address for this poster, I will
gladly continue it off-list. But to be honest, if you feel so strongly
about it, I'm happy to drop it, as your posts are more enjoyable and
topical.

- Shao Miller

Mark Storkamp 12-17-2012 12:02 AM

Re: Off-Topic: JimB Posts
 
In article <kalm2s$dco$1@dont-email.me>,
Shao Miller <sha0.miller@gmail.com> wrote:

> On 12/16/2012 17:33, Keith Thompson wrote:
> > Shao Miller <sha0.miller@gmail.com> writes:
> >> On 12/16/2012 02:40, JimB wrote:
> >>>
> >>> a big problem.
> >>>
> >>
> >> The regulars will most probably never forgive me, but...
> >>
> >> What is it that compels you to type this (above) and the "Why Jacob
> >> Navia hates C" post?

> > [snip]
> >
> > Shao, by all means feel free to waste your time asking about the
> > motivations of an obvious troll. But please don't waste everyone
> > else's time by doing it here.
> >

>
> That is why the subject clearly includes "off-topic" in it.
>
> If you can provide me with the e-mail address for this poster, I will
> gladly continue it off-list. But to be honest, if you feel so strongly
> about it, I'm happy to drop it, as your posts are more enjoyable and
> topical.
>
> - Shao Miller


You're delusional if you think you'll accomplish anything keeping it
on-list.

*plonk*


All times are GMT. The time now is 05:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.