Linux -Blue forest free software | Return to home page | Site Map | Search WWW | Contact Us | -->
Your current position : Homepage > Free Software > Technological exchanges >Application Programming -->


    

Blue Forest http://www.lslnet.com at 2:08 p.m. on August 16, 2006

Int (*fpfi (int *)) (double); This complicated formula, as I understand it (安 c99)

He defined a function, a function of the parameters int*, the function return value is a function at the target (the double function of a parameter and return value to int).
For just want to know these people, this is enough, because it is very difficult to see a complicated formula.
I saw 安 c99 standards manual, which on this parsing (this may be the wrong word) to come up with such things as the basis for analysis. Finally in this regard postings attached buttonkou (K&R seem to have used to explain the sorry, I have never seen such a classic book), more than what I wrote long :)
First be prepared, it is bypassing the. A formal language based on the rock, because it involves a change in thinking.
安 c99 the Eastern Standard Manual :
1. If the statement (declaration), "T-D1", in the form below with D1
Identifier
Then on the type of T-ident
(Note : ddd identifier mean identifier bit c should know all the basic knowledge, there are no great significance of this first from the series of stringent sake of this)
(Note : ident ddd in D1 should statement / definition of identifier, in this case is fpfi)
2. If the statement (declaration), "T-D1", in the form below with D1
(D)
Then ident and the type of statement (declaration), "TD" as a means of two brackets can be removed.
3. If the statement (declaration), "T-D1", in the form below with D1
* Type-qualifier-list (opt) D
If ident and the type of "TD" "derived-declarator-type-list T" Then ident "T-D1" is the type "pointer to derived-declarator-type-list type-qualifier-list T"
(Note : type-qualifier-list ddd is the meaning of const keyword restrict volatile combination of the three, opt mean options, which can be on this issue as this box)
(Note : derived-declarator-type-list ddd the meaning of a word or a piece that, for example, int *f;f type "pointer to int" T here is int. So is the pointer to derived-declarator-type-list)

(Note : you can take note of ddd "TD" and "T-D1" T is the beginning of this it is necessary. "derived-declarator-type-list T" "T derived-declarator-type-list type-qualifier-list pointer to the" T were last below the same, and that This is a must, then this is also translated into Chinese T on the final surface. "pointer to the" how to translate? I have here translated as "indicators pointing to the" then "derived-declarator-type-list type-qualifier-list pointer to T" translated as "derived-declarator-type-list type-qualifier-list point-T." int f f; were the type of "int", int f *f; which is the type of "point-int", a little, after the attributive home, in line with Chinese practice, but did not approach the invention c syntax is a foreigner, must ensure that the final int. )
4. If the statement (declaration), "T-D1", in the form below with D1
D (parameter-type-list)
D (identifier-list (opt))
If ident and the type of "TD" "derived-declarator-type-list T" Then ident "T-D1" is the type of "derived-declarator-type-list function returning T"
(Note : ddd "derived-declarator-type-list function returning T" Following translation, "derived-declarator-type-list function return value of T," but after a home Attribute :))
We can see that any complicated sentence to the "T identifier", the derived meaning of the whole sentence. T always be placed in the most because, and only the "T identifier" no other formula inference from this formula. Therefore, this formula is the first formula.
Int fpfi; fpfi type "int" Application of Article 1 T = "int" (hereinafter the same)
Int fpfi (int*); Fpfi types "function return value to int" application of D = 4 "fpfi" derived-declarator-type-list= ""
Int *fpfi (int*); Fpfi types "function return value of the point-int" Application of section 3 of the D = "fpfi (int*)" derived-declarator-type-list= "function return value"
Int (*fpfi (int*)); Fpfi types "function return value of the point-int" Subsection 2
Int (*fpfi (int *)) (double); fpfi types "at the function return value of the target function return value to int" application of D = 4 "(*fpfi (int *))," derived-declarator-type-list= "function return value of the indicators pointing to the"
Attribute attention after the home (not Chinese, it seems, but here no way)
"Return value to int," is modified in front of the "function" and "at the function return value to int" is the modified front of the "targets" and "indicators at the function return value to return value to int" is the modified front of the "function".
This is the case, and sort out the type : fpfi as "one function, the function return value of the indicator, the indicator at a function, the function return value to int"
Oh, enough bars around. In the process of reasoning attributive nouns and the regular home after the separation led to the attributive noun modified sentence after sentence in a modified others. So this will not be the feel, you have to push hard in the cold, and then the whole explanation.

Report : Eastern of postings on such buttonkou
---------------------buttonkou Postings started -----------
C typedef can be used to define new types to replace the existing type, but the way I see a code, not quite understand the significance of his, I am somewhat puzzled by the use of this for what? ? ?

Typedef void Sigfunc (int); LEAVES OF 13 SPECIES OF LAURACEAE for signal handlers */
Sigfunc * signal (int signo, Sigfunc * func);
* Signal static Sigfunc (int signo, Sigfunc * func); LEAVES OF 13 SPECIES OF LAURACEAE for our signal () function */
-------------------------------------------------------------------------------------------------------------------------
In fact, this function is defined in the ANSI C signal function
The function prototype is :
Void (*signal (int signo, void (*handler) (int))) (int)

Simplified
Void (*signal ()) ()

Mening : function (signal) returning pointer to function returning void

Book:the c programming language (Kernighan&Ritchie) 5.12 Complicated Declarations on the use of elaborate!

There is a simple method for your consideration :
() Function returning :
[] Array of :
* Pointer to :

* Priority which lower!

Void (*signal ()) ()

1. Signal () function returning ---->signal :
2. *signal () Function returning pointer to ----> signal :
3 (*signal ()) () function returning pointer to function returning ---->signal :
4. Void (*signal ()) () function returning --->signal pointer to function returning void :

Adding the parameters
Signal (int signo, void (*handler) (int))
---------->
Function with parameter (int. pointer to function with parameter (int) returning void) returning pointer to function returning void

Void (*signal (int signo, void (*handler) (int))) (int)
------------>

Function with parameter (int. pointer to function with parameter (int) returning void) returning pointer to function with parameter (int) returning void

Now is the c programming language (Kernighan&Ritchie) procedures

File "dcl.c"
------------------------------------
#include "Stdio.h>
#include "String.h>
#include "Ctype.h>
#include "Getch.h"

# 100 MAXTOKEN
Enum (NAME, PARANS, BRACKETS)

Void dcl (void);
Dirdcl void (void);

Int gettoken (void);
Int tokentype;
Char token[MAXTOKEN];
Char name[MAXTOKEN];
Char datatype[MAXTOKEN];
Char out[1000];

Int main (void)
{
While (gettoken ()> EOF) (
Strcpy (datatype, token);
Out[0] = '\0';
Dcl ();

If (tokentype> '\n') (
Printf ( "syntax error");
}
Printf ( "%s : %s %s\n" name, out, datatype);
}
Return 0
}

Int gettoken (void)
{
Int c, getch (void);
Void ungetch (int);
J = char token;

While ((c = getch ()) ====== '' | | c ====== '\t')
;

If (c ====== '(') (
If ((c =getch ()) ====== ')') (
Strcpy (token, "()");
Return tokentype = PARANS;
}else --
Ungetch (c);
Return tokentype = '(';
}
) Else if (c== '[') (
For (*p++ = c; (*p++ = getch ())> ']'; )
;
J = '\0';
Return tokentype = BRACKETS;
) Else if (isalpha (c)) (
For (*p++ = c; isalnum (c = getch ()); )
*p++ = C;
J = '\0';
Ungetch (c);
NABE return tokentype =
) Else (
Return tokentype = c;
}
}

Dirdcl void (void)
{
Int type;

If (tokentype ====== '(') (
Dcl ();
If (tokentype> ')')
Printf ( "error : missing) \n");
) Else if (tokentype ====== NAME)
Strcpy (name, token);
Else (
Printf ( "error : expexted name or (dcl) \n");
}

While ((type = gettoken ()) | | type ====== ====== PARANS BRACKETS) (
If (type ====== PARANS)
Strcat (out "function returning");
Else (
Strcat (out, "array");
Strcat (out, token);
Strcat (out, "of");
}
}
}

Void dcl (void)
{
Int ns;
For (ns = 0 gettoken () ====== '*'; ) (
Ns++;
}

Dirdcl ();
While (ns-- "0) (
Strcat (out, "pointer to");
}
}

File "getch.h"
----------------------
#include "Stdio.h>
Int getch (void);
Void ungetch (int);

File getch.c
-----------------

#include "Getch.h"
BUFSIZE 100 #

Char buf[BUFSIZE];
Int bufp = 0

Int getch (void)
{
Return (bufp "0)? Buf[--bufp] : getchar ();
}

Void ungetch (int c)
{
If (bufp "= BUFSIZE) (
Printf ( "ungetch : too many characters\n");
) Else (
Buf[bufp++] = c;
}
}

----- Results
Operation importation :
Char (* (*x[3]) ()) [5]
Output :
X : array[3] of pointer to function returning pointer to array[5] of char
--------------------------------------------------------------------------------------------
------
Above do not know is not right!
---------------------buttonkou Postings end -----------


Re : int (*fpfi (int *)) (double); This complicated formula, as I understand it (安

Basically correct. I think two is the wrong place :

1. "Parsing" should be "grammatical analysis."

2. Int *fpfi (int*); Fpfi types "function return value of the point-int" Application of section 3 of the D = "fpfi (int*)" derived-declarator-type-list= "function return value" -- this should be deleted.

Re : int (*fpfi (int *)) (double); This complicated formula, as I understand it (安

Syntactic grammar, where you might say, I have the time to look at.

Int fpfi (int*); Fpfi types "function return value to int"
Well, according to
---------------------------
3. If the statement (declaration), "T-D1", in the form below with D1
* Type-qualifier-list (opt) D
If ident and the type of "TD" "derived-declarator-type-list T" Then ident "T-D1" is the type "pointer to derived-declarator-type-list type-qualifier-list T"
---------------------------
CMS is in the form of D = D1 ----> "fpfi (int*)"

'And if the type ident "TD" "derived-declarator-type-list T" Then ident "T-D1" is the type "pointer to derived-declarator-type-list type-qualifier-list T" 'This quote is the upswing :
And if fpfi type "int fpfi (int*)," "function return value of T," then ident "int fpfi (int*)" is the type "pointer to function return value of T"
Then next, the correct phrase should be : 'D = "fpfi (int*)" derived-declarator-type-list= "function return value of"'

Re : int (*fpfi (int *)) (double); This complicated formula, as I understand it (安

Oh, I did not say that this step is wrong, wrong is the next step. Derivation of this step is not correct. Of course, it is possible that you mean it and the next step is derived not, but I took the opportunity to talk about it, but this is not very easy to understand the whole deduced.

Re : int (*fpfi (int *)) (double); This complicated formula, as I understand it (安

But after really are.
You want to express in some detail, what you have said is' int (*fpfi (int*)); Fpfi types "function return value of the point-int" Application of Article 2, 'there is no need for this step?
The steps that you expect?


Re : int (*fpfi (int *)) (double); This complicated formula, as I understand it (安

Oh, I think are wrong, you are right. Sorry, I let you heard so much nonsense : P



 Privacy Policy  Copyright © 1999-2000 LSLNET.COM. All rights reserved. Blue Forest website owners. E-mail : Webmaster@lslnet.com