473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

what's this?

#include<iostream>

struct zaman{
float p;
};

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

int main(){
func(-1); //Hmmm. what's this?
std::getchar();
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?

Jun 24 '07 #1
6 1599
ba****@gmail.com wrote:

Please don't multi-post on Usenet.

--
Ian Collins.
Jun 24 '07 #2
ba****@gmail.com wrote:
#include<iostream>

struct zaman{
float p;
};

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

int main(){
func(-1); //Hmmm. what's this?
std::getchar();
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?
func is a type, INTERFACE_FINDER is a type, so they can't be function
calls. Instead they're casts, -1 cast to a function pointer.

john
Jun 24 '07 #3
On Jun 25, 1:57 am, John Harrison <john_androni...@hotmail.comwrote:
bak...@gmail.com wrote:
#include<iostream>
struct zaman{
float p;
};
typedef int (*func)(zaman, int);
int main(){
func(-1); //Hmmm. what's this?
std::getchar();
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?

func is a type, INTERFACE_FINDER is a type, so they can't be function
calls. Instead they're casts, -1 cast to a function pointer.

john
I am sorry, that's why I deleted it. So, if it is a cast why doesn't
this work in c++

int* (-1);

but func(-1); works?

Jun 24 '07 #4
co****************@gmail.com wrote:
On Jun 25, 1:57 am, John Harrison <john_androni...@hotmail.comwrote:
>bak...@gmail.com wrote:
#include<iostream>
struct zaman{
float p;
};
typedef int (*func)(zaman, int);
int main(){
func(-1); //Hmmm. what's this?
std::getchar();
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?

func is a type, INTERFACE_FINDER is a type, so they can't be function
calls. Instead they're casts, -1 cast to a function pointer.

john

I am sorry, that's why I deleted it. So, if it is a cast why doesn't
this work in c++

int* (-1);

but func(-1); works?
Try:

typedef int * int_ptr;

int main ( void ) {
int_ptr(-1);
}
Best

Kai-Uwe Bux
Jun 24 '07 #5
On Jun 25, 3:42 am, Kai-Uwe Bux <jkherci...@gmx.netwrote:
comp.lang.super...@gmail.com wrote:
On Jun 25, 1:57 am, John Harrison <john_androni...@hotmail.comwrote:
bak...@gmail.com wrote:
#include<iostream>
struct zaman{
float p;
};
typedef int (*func)(zaman, int);
int main(){
func(-1); //Hmmm. what's this?
std::getchar();
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?
func is a type, INTERFACE_FINDER is a type, so they can't be function
calls. Instead they're casts, -1 cast to a function pointer.
john
I am sorry, that's why I deleted it. So, if it is a cast why doesn't
this work in c++
int* (-1);
but func(-1); works?

Try:

typedef int * int_ptr;

int main ( void ) {
int_ptr(-1);

}

Best

Kai-Uwe Bux
Goodness! This works! It seems it is due to C++ grammar. Or is it?

Jun 24 '07 #6
co****************@gmail.com wrote:
:: On Jun 25, 1:57 am, John Harrison <john_androni...@hotmail.com>
:: wrote:
::: bak...@gmail.com wrote:
:::: #include<iostream>
:::
:::: struct zaman{
:::: float p;
:::: };
:::
:::: typedef int (*func)(zaman, int);
:::
:::: int main(){
:::: func(-1); //Hmmm. what's this?
:::: std::getchar();
:::: 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?
:::
::: func is a type, INTERFACE_FINDER is a type, so they can't be
::: function calls. Instead they're casts, -1 cast to a function
::: pointer.
:::
::: john
::
:: I am sorry, that's why I deleted it. So, if it is a cast why
:: doesn't this work in c++
::
:: int* (-1);
::
:: but func(-1); works?

Because int* is two tokens, and breaks the syntax (which is just
crazy).

If you try

typedef int* ip;

ip(-1);

it compiles (but doesn't do much).
In C++ you should really use the cast syntax

static_cast<int*>(-1)

because then the compiler will tell you that it really doesn't work.
Neither does ip(-1), of course.
Bo Persson
Jun 24 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Randell D. | last post by:
I have just recompiled, upgraded to PHP 4.3.4. As an exercise (and curiosity) I've decided to test out PDF functions and got the test in the PHP online manual working. I had one problem whereby...
2
by: thecrow | last post by:
Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
9
by: Martin Maney | last post by:
In my copious spare time I've been dabbling at getting a computerized version of a board game working. After deciding that tk just made me want to vomit, and wx was like swimming through...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
3
by: Ron_Adam | last post by:
Ok... it's works! :) So what do you think? Look at the last stacked example, it process the preprocess's first in forward order, then does the postprocess's in reverse order. Which might be...
12
by: Dario | last post by:
The following simple program behaves differently in Windows and Linux . #include <stdexcept> #include <iostream> #include <string> using namespace std; class LogicError : public logic_error {...
30
by: James Conrad StJohn Foreman | last post by:
After 3 years of using DB2 on Linux, I'm leaving my current employers to go work for a SQL Server shop instead. In order to find my replacement, they're trying to put together a set of questions...
2
by: yogesh | last post by:
char TCGI::x2c(char *what) { register char digit; digit = (char) ((what >= 'A' ? ((what & 0xdf) - 'A')+10 : (what - '0'))); digit *= (char) 16; digit += (char) ((what >= 'A' ? ((what & 0xdf) -...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.