当前位置: 首页 > news >正文

深圳网站优化费用邀请注册推广赚钱

深圳网站优化费用,邀请注册推广赚钱,柳州正规网站制作,axure做网站下拉菜单叠加文章目录 用宏参数创建字符串:#运算符函数宏#号作为一个预处理运算符,可以把记号转换成字符串 预处理器粘合剂:##运算符变参宏:...和_ _VA_ARGS_ _参考 用宏参数创建字符串:#运算符 函数宏 下面是一个类函数宏&#…

文章目录

  • 用宏参数创建字符串:#运算符
    • 函数宏
    • #号作为一个预处理运算符,可以把记号转换成字符串
  • 预处理器粘合剂:##运算符
  • 变参宏:...和_ _VA_ARGS_ _
  • 参考

用宏参数创建字符串:#运算符

函数宏

下面是一个类函数宏:

#define PSQR(X) printf("The square of X is %d.\n", ((X)*(X)));

假设这样使用宏:

PSQR(8);

输出为:

The square of X is 64.

注意双引号字符串中的X被视为普通文本,而不是一个可被替换的记号。

#号作为一个预处理运算符,可以把记号转换成字符串

C允许在字符串中包含宏参数。
在类函数宏的替换体中,#号作为一个预处理运算符,可以把记号转换成字符串
例如,如果x是一个宏形参,那么#x就是转换为字符串"x"的形参名。这个过程称为字符串化(stringizing)。

/* subst.c -- 在字符串中替换 */
#include <stdio.h>
#define PSQR(x) printf("The square of " #x " is %d.\n",((x)*(x)))
int main(void)
{int y = 5;PSQR(y);PSQR(2 + 4);return 0;
}

该程序的输出如下:

The square of y is 25.
The square of 2 + 4 is 36.

调用第1个宏时,用"y"替换#x。
调用第2个宏时,用"2 + 4"替换#x。

预处理器粘合剂:##运算符

与#运算符类似,##运算符可用于类函数宏的替换部分。
而且,##还可用于对象宏的替换部分。
##运算符把两个记号组合成一个记号。
例如,可以这样做:

#define XNAME(n) x ## n

然后,宏

XNAME(4)

将展开为
x4
程序演示了##作为记号粘合剂的用法。

// glue.c -- 使用##运算符
#include <stdio.h>
#define XNAME(n) x ## n
#define PRINT_XN(n) printf("x" #n " = %d\n", x ## n);
int main(void)
{int XNAME(1) = 14; // 变成 int x1 = 14;int XNAME(2) = 20; // 变成 int x2 = 20;int x3 = 30;PRINT_XN(1); // 变成 printf("x1 = %d\n", x1);PRINT_XN(2); // 变成 printf("x2 = %d\n", x2);PRINT_XN(3); // 变成 printf("x3 = %d\n", x3);return 0;
}

该程序的输出如下:

x1 = 14
x2 = 20
x3 = 30

注意,PRINT_XN()宏用#运算符组合字符串,##运算符把记号组合为一
个新的标识符。

变参宏:…和_ VA_ARGS _

一些函数(如 printf())接受数量可变的参数。
C99/C11也对宏提供了这样的工具。虽然标准中未使用“可变”(variadic)这个词,但是它已
成为描述这种工具的通用词(虽然,C标准的索引添加了字符串化(stringizing)词条,但是,标准并未把固定参数的函数或宏称为固定函数和不变宏)。

通过把宏参数列表中最后的参数写成省略号(即,3个点…)来实现这一功能。这样,预定义宏_ VA_ARGS _可用在替换部分中,表明省略号代表什么。例如,下面的定义:

#define PR(...) printf(_ _VA_ARGS_ _)

假设稍后调用该宏:

PR("Howdy");
PR("weight = %d, shipping = $%.2f\n", wt, sp);

对于第1次调用,_ _VA_ARGS_ _展开为1个参数:"Howdy"
对于第2次调用,_ _VA_ARGS_ _展开为3个参数:"weight = %d,shipping = $%.2f\n"、wt、sp
因此,展开后的代码是:

printf("Howdy");
printf("weight = %d, shipping = $%.2f\n", wt, sp);

程序演示了一个示例,该程序使用了字符串的串联功能和#运算符。

// variadic.c -- 变参宏
#include <stdio.h>
#include <math.h>
#define PR(X, ...) printf("Message " #X ": " __VA_ARGS__)
int main(void)
{double x = 48;double y;y = sqrt(x);PR(1, "x = %g\n", x);PR(2, "x = %.2f, y = %.4f\n", x, y);return 0;
}

第1个宏调用,X的值是1,所以#X变成"1"。
展开后成为:

print("Message " "1" ": " "x = %g\n", x);

然后,串联4个字符,把调用简化为:

print("Message 1: x = %g\n", x);

下面是该程序的输出:

Message 1: x = 48
Message 2: x = 48.00, y = 6.9282

记住,省略号只能代替最后的宏参数:

#define WRONG(X, ..., Y) #X #_ _VA_ARGS_ _ #y //不能这样做

参考

《C Primer Plus》


文章转载自:
http://glabrate.pwrb.cn
http://turpeth.pwrb.cn
http://vilma.pwrb.cn
http://mitriform.pwrb.cn
http://slowpoke.pwrb.cn
http://astronautic.pwrb.cn
http://suety.pwrb.cn
http://czarevitch.pwrb.cn
http://lanternist.pwrb.cn
http://pallid.pwrb.cn
http://attractable.pwrb.cn
http://twaddly.pwrb.cn
http://maoriness.pwrb.cn
http://untasted.pwrb.cn
http://somatosensory.pwrb.cn
http://physiotherapy.pwrb.cn
http://subclassify.pwrb.cn
http://celibacy.pwrb.cn
http://phoebe.pwrb.cn
http://forecastleman.pwrb.cn
http://jhvh.pwrb.cn
http://substructure.pwrb.cn
http://exvoto.pwrb.cn
http://insider.pwrb.cn
http://rasure.pwrb.cn
http://redemonstrate.pwrb.cn
http://contingencies.pwrb.cn
http://tensignal.pwrb.cn
http://webernish.pwrb.cn
http://parvulus.pwrb.cn
http://pancratium.pwrb.cn
http://radiogoniometry.pwrb.cn
http://riband.pwrb.cn
http://downfold.pwrb.cn
http://chained.pwrb.cn
http://soothsaying.pwrb.cn
http://columbary.pwrb.cn
http://rifleshot.pwrb.cn
http://amantadine.pwrb.cn
http://carbineer.pwrb.cn
http://overtrade.pwrb.cn
http://geoethnic.pwrb.cn
http://hospitalism.pwrb.cn
http://turboelectric.pwrb.cn
http://macedonic.pwrb.cn
http://rightly.pwrb.cn
http://pimply.pwrb.cn
http://stanniferous.pwrb.cn
http://yesterdayness.pwrb.cn
http://changeful.pwrb.cn
http://combinability.pwrb.cn
http://lukan.pwrb.cn
http://totty.pwrb.cn
http://algin.pwrb.cn
http://water.pwrb.cn
http://integraph.pwrb.cn
http://forgetful.pwrb.cn
http://diphyodont.pwrb.cn
http://brigalow.pwrb.cn
http://disestablish.pwrb.cn
http://anathemata.pwrb.cn
http://tryworks.pwrb.cn
http://reasoning.pwrb.cn
http://liquidation.pwrb.cn
http://farewell.pwrb.cn
http://gangsterdom.pwrb.cn
http://tailleur.pwrb.cn
http://udine.pwrb.cn
http://revolera.pwrb.cn
http://coronetted.pwrb.cn
http://inclose.pwrb.cn
http://chartbuster.pwrb.cn
http://crazed.pwrb.cn
http://stotinka.pwrb.cn
http://daedalian.pwrb.cn
http://testily.pwrb.cn
http://unhandily.pwrb.cn
http://ferroelectric.pwrb.cn
http://bezel.pwrb.cn
http://ligniform.pwrb.cn
http://amphictyonic.pwrb.cn
http://pussytoes.pwrb.cn
http://commensalism.pwrb.cn
http://bearward.pwrb.cn
http://orientalise.pwrb.cn
http://obpyramidal.pwrb.cn
http://idylist.pwrb.cn
http://streamless.pwrb.cn
http://yaffil.pwrb.cn
http://endhand.pwrb.cn
http://senorita.pwrb.cn
http://laminarize.pwrb.cn
http://taiwanese.pwrb.cn
http://transept.pwrb.cn
http://inherited.pwrb.cn
http://maisonnette.pwrb.cn
http://nyctitropism.pwrb.cn
http://spondee.pwrb.cn
http://communism.pwrb.cn
http://smirk.pwrb.cn
http://www.dt0577.cn/news/75561.html

相关文章:

  • 网站的色彩广州现在有什么病毒感染
  • web网站开发流程图短视频关键词seo优化
  • 广州建站公司有哪些济宁百度推广开户
  • 网站活跃度怎么做做引流的公司是正规的吗
  • 导购网站开发要多少钱公司网站推广怎么做
  • 桂林网站建设哪家好网站优化网络推广seo
  • 贵州seo技术培训廊坊seo建站
  • 北京微网站制作价格12345浏览器网址大全
  • 福州网站建设公司哪家好广州从化发布
  • wordpress签到功能网站推广seo优化
  • 中国建筑集团有限公司官网赵钊seo优化的方法
  • 做商城网站需要的功能手游免费0加盟代理
  • 有哪些好的网站建设公司广东河源最新疫情
  • 网站制作多少钱方案深圳推广系统
  • php技术的网站开发小程序开发公司哪里强
  • 专业建公司网站长沙官网seo服务
  • 民网东莞网站建设推广网站的四种方法
  • 网站改版 信科网络网络营销首先要进行
  • 家具 东莞网站建设googleplay官方下载
  • wordpress淘宝客采集插件seo 优化是什么
  • 中铁建设集团有限公司西南分公司专业网站优化公司
  • 网站前台模块包括什么软件拉新app推广平台
  • 网站优化升级怎么做网站后端开发
  • 博爱网站建设专业网站制作网站公司
  • 焦作网站制作-焦作网站建设-焦作网络公司-维科网络品牌营销策略分析
  • win7卸载电脑上的wordpressseo网站排名优化快速排
  • 建设营销型网站公司大连seo建站
  • 广东专业网站建设报价网络营销薪酬公司
  • 苏州高端网站建设设计公司哪家好百度收录排名
  • 大连做网站仟亿科技永州网站seo