C语言声明优先级(precedence rule)

以下文字摘自expert c programming

A    Declarations are read by starting with the name and then reading in precedence order.


B The precedence, from high to low, is:
B.1 parentheses grouping together parts of a declaration
B.2 the postfix operators:
parentheses () indicating a function, and
square brackets [] indicating an array.
B.3 the prefix operator: the asterisk denoting "pointer to".


C      If a const and/or volatile keyword is next to a type specifier (e.g. int, long, etc.) it

applies to the type specifier. Otherwise the const and/or volatile keyword applies to the

pointer asterisk on its immediate left.

个人觉得这里next to理解为adjacent to而不是after,中文版的译者翻译成的是after的意思。

相当于说const,volatile与类型说明符刚好挨着,那么它修饰类型说明符。否则它与左边的*(星号)左结合,修饰左边的星号


const int * grape


const 修饰int,代表常量,grape为指向const int类型的指针


int const * grape

const修饰int,const int与int const等价


int* const grape_jelly

这里const修饰的是*,意味着grape_jelly是个指针常量

不能修改grape_jelly使它指向其他的对象



static STATUS _fptIpRule2ConfigObj(TPCONFIG_SET_INPUT *stInput, char *tblKey, FPT_IP_RULE *ipRule, INT64 score) { PFM_IF_FAIL_RET_VAL(tpConfig_objAddKeyScoreForSet(stInput, TPCONFIG_INIT_ENTRY, tblKey, score), ERR_BAD_PARAM); PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldNumU8ForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_LOGGING, ipRule->logging), ERR_BAD_PARAM); if (ipRule->ipRule.ipValid.sIpEnable) { char sipStr[IP_ADDRESS_LENGTH] = {}; char sipMaskStr[IP_ADDRESS_LENGTH] = {}; FPT_IPADDR_ARRAY_TO_IPSTR(ipRule->ipRule.sourceAddress.ipAddr, sipStr); FPT_IPADDR_ARRAY_TO_IPSTR(ipRule->ipRule.sourceAddressMask.ipAddr, sipMaskStr); PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldStrForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_SIP, sipStr), ERR_BAD_PARAM); PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldStrForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_SIP_MASK, sipMaskStr), ERR_BAD_PARAM); } if (ipRule->ipRule.ipValid.dIpEnable) { char dipStr[IP_ADDRESS_LENGTH] = {}; char dipMaskStr[IP_ADDRESS_LENGTH] = {}; FPT_IPADDR_ARRAY_TO_IPSTR(ipRule->ipRule.destAddress.ipAddr, dipStr); FPT_IPADDR_ARRAY_TO_IPSTR(ipRule->ipRule.destAddressMask.ipAddr, dipMaskStr); PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldStrForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_DIP, dipStr), ERR_BAD_PARAM); PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldStrForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_DIP_MASK, dipMaskStr), ERR_BAD_PARAM); } if(ipRule->ipRule.ipValid.ipDscpValid) { PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldNumU8ForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_DSCP, ipRule->ipRule.ipDscp), ERR_BAD_PARAM); } if(ipRule->ipRule.ipValid.ipTosValid) { PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldNumU8ForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_TOS, ipRule->ipRule.ipTos), ERR_BAD_PARAM); } if(ipRule->ipRule.ipValid.ipPreValid) { PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldNumU8ForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_PRE, ipRule->ipRule.ipPre), ERR_BAD_PARAM); } if(ipRule->ipRule.ipValid.ipProtoValid) { PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldNumU8ForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_IP_PROTO, ipRule->ipRule.ipProto), ERR_BAD_PARAM); } if(ipRule->ipRule.ipValid.l4SourcePortValid) { PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldNumU32ForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_SPORT, ipRule->ipRule.fptL4Struct.sport), ERR_BAD_PARAM); PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldNumU32ForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_SPORT_MASK, ipRule->ipRule.fptL4Struct.spMask), ERR_BAD_PARAM); } if(ipRule->ipRule.ipValid.l4DestPortValid) { PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldNumU32ForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_DPORT, ipRule->ipRule.fptL4Struct.dport), ERR_BAD_PARAM); PFM_IF_FAIL_RET_VAL(tpConfig_objAddFieldNumU32ForSet(stInput, TPCONFIG_INIT_ENTRY, IP_FPT_RULE_DPORT_MASK, ipRule->ipRule.fptL4Struct.dpMask), ERR_BAD_PARAM); } return ERR_NO_ERROR; }
最新发布
10-01
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值