Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

what's this?

 
 
Keith Thompson
Guest
Posts: n/a
 
      06-24-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:
> 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?

[snip]

> sorry for the typo, it is:
>
> typedef int (*func)(filo, int);


Ok, so your code is:

struct filo{
float p;
};

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

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

When I try to compile it, I get a parse error on "func(-1);".

If it works for you, then it's because the code you posted is not the
same as the code you compiled.

If you post code here, *always* copy-and-paste it; never attempt to
re-type it. There was at least one error in the code you originally
posted (the one you corrected in a followup); there must be more
errors than that.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <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"
 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      06-25-2007
On Sun, 24 Jun 2007 20:48:12 -0000, (E-Mail Removed) wrote:

>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);


If filo were a type, this would define the type func as being a
synonym for the type pointer to function taking two arguments (first
of type filo, second of type int) and returning int. Since filo is
not a type, this is just a syntax error.

Define what you mean by working. Is it merely the absence of a
diagnostic? If so, then maybe you can raise the warning level on your
system. Or maybe your compiler has an error. Have you looked at the
generated code to see what it does, if anything. Have you stepped
through it with a debugger.

And if your compiler accepts the typedef, you are operating in the
realm of compiler extensions. Maybe func(-1) is another such
extension. You should ask in a group where your compiler is topical.


Remove del for email
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      06-25-2007
Keith Thompson said:

<snip>

> When I try to compile it, I get a parse error on "func(-1);".
>
> If it works for you, then it's because the code you posted is not the
> same as the code you compiled.


Or the language he's asking about is not the same as the language he is
using.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
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