Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > what's this?

Reply
Thread Tools

what's this?

 
 
bakzam@gmail.com
Guest
Posts: n/a
 
      06-24-2007
struct filo{
float p;
};

typedef int (*func)filo, int);

int main(void){
func(-1); //Hmmm. what's this?
return 0;
}

why is func(-1) working?

Actually, I found this (equivalent code) in DON BOX's book

--------------------
typedef HRESULT (*INTERFACE_FINDER) (void *pThis, DWORD dwData, REFIID
riid, void **ppv);

//pseudo-function to indicate entry is just an offset
#define ENTRY_IS_OFFSET INTERFACE_FINDER(-1)
--------------

Isn't INTERFACE_FINDER(-1) a call to a function? How is it an offset?

 
Reply With Quote
 
 
 
 
bakzam@gmail.com
Guest
Posts: n/a
 
      06-24-2007
On Jun 25, 1:46 am, (E-Mail Removed) wrote:
> struct filo{
> float p;
>
> };
>
> typedef int (*func)filo, int);
>
> int main(void){
> func(-1); //Hmmm. what's this?
> return 0;
>
> }
>
> why is func(-1) working?
>
> Actually, I found this (equivalent code) in DON BOX's book
>
> --------------------
> typedef HRESULT (*INTERFACE_FINDER) (void *pThis, DWORD dwData, REFIID
> riid, void **ppv);
>
> //pseudo-function to indicate entry is just an offset
> #define ENTRY_IS_OFFSET INTERFACE_FINDER(-1)
> --------------
>
> Isn't INTERFACE_FINDER(-1) a call to a function? How is it an offset?


sorry for the typo, it is:

typedef int (*func)(filo, int);

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      06-24-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> sorry for the typo, it is:
>
> typedef int (*func)(filo, int);
>

It's a pointer to a function returning int which has a filo and an int
as its parameters.

--
Ian Collins.
 
Reply With Quote
 
bakzam@gmail.com
Guest
Posts: n/a
 
      06-24-2007
On Jun 25, 1:58 am, Ian Collins <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > sorry for the typo, it is:

>
> > typedef int (*func)(filo, int);

>
> It's a pointer to a function returning int which has a filo and an int
> as its parameters.
>
> --
> Ian Collins.


that's not what I asked!! I wanted to know about the statement

func(-1);

and about the macro INTERFACE_FINDER(-1)

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      06-24-2007
(E-Mail Removed) wrote:
> On Jun 25, 1:58 am, Ian Collins <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>>> sorry for the typo, it is:
>>> typedef int (*func)(filo, int);

>> It's a pointer to a function returning int which has a filo and an int
>> as its parameters.
>>
>> --
>> Ian Collins.

>
> that's not what I asked!! I wanted to know about the statement
>
> func(-1);
>
> and about the macro INTERFACE_FINDER(-1)
>

Which you don't show, so how can anyone give yo an answer?

The original code you posted was nonsense.

--
Ian Collins.
 
Reply With Quote
 
bakzam@gmail.com
Guest
Posts: n/a
 
      06-24-2007
On Jun 25, 2:16 am, Ian Collins <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > On Jun 25, 1:58 am, Ian Collins <(E-Mail Removed)> wrote:
> >> (E-Mail Removed) wrote:
> >>> sorry for the typo, it is:
> >>> typedef int (*func)(filo, int);
> >> It's a pointer to a function returning int which has a filo and an int
> >> as its parameters.

>
> >> --
> >> Ian Collins.

>
> > that's not what I asked!! I wanted to know about the statement

>
> > func(-1);

>
> > and about the macro INTERFACE_FINDER(-1)

>
> Which you don't show, so how can anyone give yo an answer?
>
> The original code you posted was nonsense.
>
> --
> Ian Collins.


OK, But what about

func(-1);

It is not non-sense. There has to be a reason as to why is it not
giving error. I think it is creating a constant function pointer, or
something like that. I am not sure, so have asked this question.

 
Reply With Quote
 
bakzam@gmail.com
Guest
Posts: n/a
 
      06-24-2007
On Jun 25, 2:21 am, (E-Mail Removed) wrote:
> On Jun 25, 2:16 am, Ian Collins <(E-Mail Removed)> wrote:
>
>
>
> > (E-Mail Removed) wrote:
> > > On Jun 25, 1:58 am, Ian Collins <(E-Mail Removed)> wrote:
> > >> (E-Mail Removed) wrote:
> > >>> sorry for the typo, it is:
> > >>> typedef int (*func)(filo, int);
> > >> It's a pointer to a function returning int which has a filo and an int
> > >> as its parameters.

>
> > >> --
> > >> Ian Collins.

>
> > > that's not what I asked!! I wanted to know about the statement

>
> > > func(-1);

>
> > > and about the macro INTERFACE_FINDER(-1)

>
> > Which you don't show, so how can anyone give yo an answer?

>
> > The original code you posted was nonsense.

>
> > --
> > Ian Collins.

>
> OK, But what about
>
> func(-1);
>
> It is not non-sense. There has to be a reason as to why is it not
> giving error. I think it is creating a constant function pointer, or
> something like that. I am not sure, so have asked this question.


Moreover, I wanted to know what can someone interpret from the
following two lines:

---------------------
typedef HRESULT (*INTERFACE_FINDER) (void *pThis, DWORD dwData, REFIID
riid, void **ppv);

//pseudo-function to indicate entry is just an offset
#define ENTRY_IS_OFFSET INTERFACE_FINDER(-1)
----------------

Don Box uses this to automate (table driven process) to implement
QueryInterface.

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      06-24-2007
(E-Mail Removed) wrote:
> On Jun 25, 2:16 am, Ian Collins <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>>> On Jun 25, 1:58 am, Ian Collins <(E-Mail Removed)> wrote:
>>>> (E-Mail Removed) wrote:
>>>>> sorry for the typo, it is:
>>>>> typedef int (*func)(filo, int);
>>>> It's a pointer to a function returning int which has a filo and an int
>>>> as its parameters.
>>>> --
>>>> Ian Collins.
>>> that's not what I asked!! I wanted to know about the statement
>>> func(-1);
>>> and about the macro INTERFACE_FINDER(-1)

>> Which you don't show, so how can anyone give yo an answer?
>>
>> The original code you posted was nonsense.
>>

*Please* don't quote signatures.
>
> OK, But what about
>
> func(-1);
>
> It is not non-sense. There has to be a reason as to why is it not
> giving error. I think it is creating a constant function pointer, or
> something like that. I am not sure, so have asked this question.
>

It is nonsense, you have declared func as a type, you can't initialise a
type that way in C (are you thinking C++?).

You could write

func f = (func)-1;

--
Ian Collins.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      06-24-2007
(E-Mail Removed) wrote:
> On Jun 25, 2:21 am, (E-Mail Removed) wrote:
>> On Jun 25, 2:16 am, Ian Collins <(E-Mail Removed)> wrote:
>>
>>
>>
>>> (E-Mail Removed) wrote:
>>>> On Jun 25, 1:58 am, Ian Collins <(E-Mail Removed)> wrote:
>>>>> (E-Mail Removed) wrote:
>>>>>> sorry for the typo, it is:
>>>>>> typedef int (*func)(filo, int);
>>>>> It's a pointer to a function returning int which has a filo and an int
>>>>> as its parameters.
>>>>> --
>>>>> Ian Collins.
>>>> that's not what I asked!! I wanted to know about the statement
>>>> func(-1);
>>>> and about the macro INTERFACE_FINDER(-1)
>>> Which you don't show, so how can anyone give yo an answer?
>>> The original code you posted was nonsense.
>>> --
>>> Ian Collins.

>> OK, But what about
>>
>> func(-1);
>>
>> It is not non-sense. There has to be a reason as to why is it not
>> giving error. I think it is creating a constant function pointer, or
>> something like that. I am not sure, so have asked this question.


I can think of two reasons why it doesn't produce
an error: First, the compiler may be broken. Second,
you may have mis-transcribed the code.

> Moreover, I wanted to know what can someone interpret from the
> following two lines:
>
> ---------------------
> typedef HRESULT (*INTERFACE_FINDER) (void *pThis, DWORD dwData, REFIID
> riid, void **ppv);


This says: "INTERFACE_FINDER is a pointer to functions
that take four arguments of type void*, DWORD, REFIID, and void**,
and that return a value of type HRESULT."

> //pseudo-function to indicate entry is just an offset
> #define ENTRY_IS_OFFSET INTERFACE_FINDER(-1)


This says "Wherever the identifier ENTRY_IS_OFFSET appears
in the source, replace it with the five-token sequence

INTERFACE_FINDER
(
-
1
)

.." Since the expanded token sequence would be nonsense, I
suspect another transcription error (are you sure there aren't
more parentheses?) or else a #define INTERFACE_FINDER somewhere
else in the code.

--
Eric Sosman
acm-dot-org.invalid
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      06-24-2007
(E-Mail Removed) wrote:
>
> Moreover, I wanted to know what can someone interpret from the
> following two lines:
>
> ---------------------
> typedef HRESULT (*INTERFACE_FINDER) (void *pThis, DWORD dwData, REFIID
> riid, void **ppv);
>
> //pseudo-function to indicate entry is just an offset
> #define ENTRY_IS_OFFSET INTERFACE_FINDER(-1)
> ----------------
>
> Don Box uses this to automate (table driven process) to implement
> QueryInterface.
>

As I said elsethread, you don't show ENTRY_IS_OFFSET.

--
Ian Collins.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments