What is the meaning of these lines?


N

nas

Hi..Please tell me what is the meaning of these lines

static IFastString *(*pfnlr)(const char *)=0

and

IFastString *(**ppfn)(const char *)=pfnlr

Where IFastString is the abstract class
 
Ad

Advertisements

G

Gianni Mariani

nas said:
Hi..Please tell me what is the meaning of these lines

static IFastString *(*pfnlr)(const char *)=0

pfnlr is a pointer to a function.

- start from the inside and read out - like this

pfnlr ->Is A

* pfnlr -> pointer

(* pfnlr)(...) -> to a function

(* pfnlr)(const char *) -> that takes a const char * as a parameter

* (* pfnlr)(const char *) -> and returns a pointer

IFastString *(*pfnlr)(const char *) -> to an IFastString

static IFastString *(*pfnlr)(const char *) -> it's got static storage

static IFastString *(*pfnlr)(const char *)=0 -> and init to nul

e.g. The above definition is the same as:

typedef IFastString *(* T)(const char *);

static T pfnlr = 0;

In this case the "= 0" initialization is implicit for static so it's not
needed.
and

IFastString *(**ppfn)(const char *)=pfnlr

That would be the same as.

T * ppfn = pfnlr; // probably an error

.... should be

T * ppfn = & pfnlr;
Where IFastString is the abstract class

It's irrelevant what IFastString is in this discussion.
 
N

nas

pfnlr is a pointer to a function.

- start from the inside and read out - like this

pfnlr ->Is A

* pfnlr -> pointer

(* pfnlr)(...) -> to a function

(* pfnlr)(const char *) -> that takes a const char * as a parameter

* (* pfnlr)(const char *) -> and returns a pointer

IFastString *(*pfnlr)(const char *) -> to an IFastString

static IFastString *(*pfnlr)(const char *) -> it's got static storage

static IFastString *(*pfnlr)(const char *)=0 -> and init to nul

e.g. The above definition is the same as:

typedef IFastString *(* T)(const char *);

static T pfnlr = 0;

In this case the "= 0" initialization is implicit for static so it's not
needed.





That would be the same as.

T * ppfn = pfnlr; // probably an error

... should be

T * ppfn = & pfnlr;




It's irrelevant what IFastString is in this discussion.

Thank you soo much for ur reply...But now i have another question to
ask..
e.g. The above definition is the same as:

typedef IFastString *(* T)(const char *);

How is this possible?? I think syntax of the type def should be for
ex:

typedef int NINT... So whenever you write NINT, compiler replaces NINT
with int..

But in your case
typedef IFastString *(* T)(const char *);

static T pfnlr = 0;

How does complier work?
 
Z

Zeppe

nas said:
How is this possible?? I think syntax of the type def should be for
ex:

typedef int NINT... So whenever you write NINT, compiler replaces NINT
with int..

you declare an int variable as

int a;

and a function pointer as

IFastString *(* a)(const char *);

as gianni explained. In the same way, you typedef an int as:

typedef int T;

and typedef a function pointer as:

IFastString *(* T)(const char *);

the syntax is specular. After the last typedef, the compiler will
replace every

T a;

with

IFastString *(* a)(const char *);

Regards,

Zeppe
 
N

nas

you declare an int variable as

int a;

and a function pointer as

IFastString *(* a)(const char *);

as gianni explained. In the same way, you typedef an int as:

typedef int T;

and typedef a function pointer as:

IFastString *(* T)(const char *);

the syntax is specular. After the last typedef, the compiler will
replace every

T a;

with

IFastString *(* a)(const char *);

Regards,

Zeppe

problem solved!!! thanks for all of u
 
Ad

Advertisements

N

nas

you declare an int variable as

int a;

and a function pointer as

IFastString *(* a)(const char *);

as gianni explained. In the same way, you typedef an int as:

typedef int T;

and typedef a function pointer as:

IFastString *(* T)(const char *);

the syntax is specular. After the last typedef, the compiler will
replace every

T a;

with

IFastString *(* a)(const char *);

Regards,

Zeppe

problem solved!!! thanks for all of u
 
Ad

Advertisements


Top