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

网站推广优化趋势互联网推广方式

网站推广优化趋势,互联网推广方式,北京网站开发招聘58,做兼职的设计网站有哪些工作目录 宏定义 宏函数 1.注释事项 2.注意事项 宏(Macro)用法 常量定义 简单函数实现 类型检查 条件编译 宏函数计算参数个数 宏定义进行类型转换 宏定义进行位操作 宏定义进行断言 总结 宏定义 #include "stdio.h" #include "string.h" #incl…

目录

宏定义

宏函数

1.注释事项

2.注意事项

宏(Macro)用法

常量定义

简单函数实现

类型检查

条件编译

宏函数计算参数个数

宏定义进行类型转换

宏定义进行位操作

宏定义进行断言

总结


宏定义

#include "stdio.h"
#include "string.h"
#include "stdlib.h"#define MAX 1025 //定义宏int main() 
{system("pause");return EXIT_SUCCESS;
}

宏函数

宏函数通常将一些比较频繁,短小的函数封装为宏函数。减少一些入栈,出栈的时间消耗。

在C语言中,宏(Macro)是预处理器的一种功能,它允许你定义一种简写形式来代替一段特定的代码。宏定义的基本形式如下:

#include "stdio.h"
#include "string.h"
#include "stdlib.h"#define MYADD(x,y) x + y //宏函数int main() 
{int a = 10;int b = 20;printf("a+b = %d\n",MYADD(a,b));system("pause");return EXIT_SUCCESS;
}

运行结果:

宏函数在预处理中做了一个替换 就是将 a 和 b替换成x和y。

宏函数是使用宏定义的函数风格的宏。它们可以像普通函数那样调用,但最终会被预处理器替换成相应的代码,减少入栈,出栈的时间。

1.注释事项

宏函数要保证运算的完整性才能执行,可以查看下面代码处理流程

#include "stdio.h"
#include "string.h"
#include "stdlib.h"#define MYADD(x,y) x + y //宏函数int main() 
{int a = 10;int b = 20;int result = MYADD(a, b) * 10;printf("result = %d\n", result);system("pause");return EXIT_SUCCESS;
}

打印结果

从上面结果来看,10 + 20 * 10 结果是等于300才符合我们预期,这个是运算完整性导致的。就是先乘除后加减问题

这个问题是可以解决的,通过()来处理,

#define MYADD(x,y) ((x) + (y)) //宏函数

2.注意事项

宏函数在一定的程度上会比普通的函数效率高

#include "stdio.h"
#include "string.h"
#include "stdlib.h"#define MYADD(x,y) ((x) + (y)) //宏函数void myAdd(int x,int y) { //x会在栈上定义,y也会 . 所以宏函数会有一定优势return x + y;
}int main() 
{int a = 10;int b = 20;int result = MYADD(a, b) * 10;printf("result = %d\n", result);system("pause");return EXIT_SUCCESS;
}

可以从宏函数,和普通函数对比,一个没有栈的开销,一个有开销。

普通函数会有入栈和出栈时间上的开销

宏(Macro)用法

常量定义

#include "stdio.h"
#include "string.h"
#include "stdlib.h"#define MAX 1024int main() 
{printf("MAX = %d\n", MAX);system("pause");return EXIT_SUCCESS;
}

运行结果

有参数宏

#include "stdio.h"
#include "string.h"
#include "stdlib.h"#define MYADD(x,y) ((x) + (y)) //宏函数int main() 
{int a = 10;int b = 20;int result = MYADD(a, b);printf("result = %d\n", result);system("pause");return EXIT_SUCCESS;
}

运行结果:

宏运算链接符

#include "stdio.h"
#include "string.h"
#include "stdlib.h"#define MAX 100
#define ROW 100
#define GET_MAX(x,y) \
x = x+y;\
y = x+y;int main() 
{int a = 10;int b = 10;GET_MAX(a, b)printf("random %d  %d\n\n", a,b);system("pause");return EXIT_SUCCESS;
}

从上面代码来看\表示链接符号,运行完第一个,就执行第二个

 无参数宏

#include "stdio.h"
#include "string.h"
#include "stdlib.h"#define MAX 100
#define ROW 100
#define RANDOM (-1.0 + 2.0*(double)rand() / RAND_MAX)int main() 
{int v = 10;printf("random %lf\n\n",RANDOM);system("pause");return EXIT_SUCCESS;
}

类型检查

#include "stdio.h"
#include "string.h"
#include "stdlib.h"#define CHECK_TYPE(a) generic((a), \int: printf("int"), \char: printf("char"), \float: printf("float"), \default: printf("other type") \
)int main() 
{int v = 10;//CHECK_TYPE(v);printf("%s", _Generic(v));system("pause");return EXIT_SUCCESS;
}

条件编译

#include "stdio.h"
#include "string.h"
#include "stdlib.h"#define DEBUG#ifdef DEBUG
#define PRINT_DEBUG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define PRINT_DEBUG(fmt, ...)
#endifint main() 
{int v = 10;char value[] = "达帮主";PRINT_DEBUG("%s\n",value);system("pause");return EXIT_SUCCESS;
}

运行结果:

如果删掉define就不会有打印

宏函数计算参数个数

#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define VA_SIZE(...) \GET_MACRO(__VA_ARGS__, 4, 3, 2, 1, 0)#define SHOW_PARAM_COUNT(...) \printf("Number of parameters: %d\n", VA_SIZE(__VA_ARGS__))// 使用
SHOW_PARAM_COUNT(1, 2); // 输出:Number of parameters: 2

宏定义进行类型转换

#define CONTAINER_OF(ptr, type, member) \((type *)((char *)(ptr) - (char *) &((type *)0)->member))

宏定义进行位操作

#define SET_BIT(x, bit) ((x) |= (1 << (bit)))
#define CLEAR_BIT(x, bit) ((x) &= ~(1 << (bit)))
#define FLIP_BIT(x, bit) ((x) ^= (1 << (bit)))
#define GET_BIT(x, bit) (((x) >> (bit)) & 1)

宏定义进行断言

#define ASSERT(expr) \if (!(expr)) { \printf("Assertion failed: %s\n", #expr); \exit(1); \}

总结

1.宏函数要保证运算的完整性。

2.宏函数在一定程度上,会比普通函数效率高,普通函数会有入栈和出栈时间上的开销。

3.通常会吧调用频繁的,短小的函数封装为宏函数。

4.宏函数的优点,以空间换时间。


文章转载自:
http://brazilwood.rdgb.cn
http://biota.rdgb.cn
http://optical.rdgb.cn
http://unpleasing.rdgb.cn
http://widish.rdgb.cn
http://rosebud.rdgb.cn
http://geocentric.rdgb.cn
http://domination.rdgb.cn
http://plowing.rdgb.cn
http://heliosis.rdgb.cn
http://wilding.rdgb.cn
http://leaching.rdgb.cn
http://planning.rdgb.cn
http://artlessly.rdgb.cn
http://unmeaning.rdgb.cn
http://yogism.rdgb.cn
http://anglomaniacal.rdgb.cn
http://folsom.rdgb.cn
http://edmund.rdgb.cn
http://jones.rdgb.cn
http://psychrotolerant.rdgb.cn
http://virga.rdgb.cn
http://begat.rdgb.cn
http://sloot.rdgb.cn
http://linlithgowshire.rdgb.cn
http://intricately.rdgb.cn
http://holocrine.rdgb.cn
http://unpardoning.rdgb.cn
http://fmcs.rdgb.cn
http://enteritis.rdgb.cn
http://constitutional.rdgb.cn
http://pediatry.rdgb.cn
http://rideable.rdgb.cn
http://quoteprice.rdgb.cn
http://misprice.rdgb.cn
http://rotten.rdgb.cn
http://anchusin.rdgb.cn
http://mameluke.rdgb.cn
http://lienable.rdgb.cn
http://transjordania.rdgb.cn
http://antenna.rdgb.cn
http://consequence.rdgb.cn
http://adultness.rdgb.cn
http://exnihilo.rdgb.cn
http://frigidaria.rdgb.cn
http://meticulosity.rdgb.cn
http://oblige.rdgb.cn
http://rheumatoid.rdgb.cn
http://absquatulation.rdgb.cn
http://krooboy.rdgb.cn
http://stanislaus.rdgb.cn
http://continent.rdgb.cn
http://astarte.rdgb.cn
http://exasperating.rdgb.cn
http://snobol.rdgb.cn
http://calciform.rdgb.cn
http://counterdrug.rdgb.cn
http://radiocarbon.rdgb.cn
http://arsenicate.rdgb.cn
http://labialization.rdgb.cn
http://redemonstrate.rdgb.cn
http://rationalise.rdgb.cn
http://sleepwalking.rdgb.cn
http://clifton.rdgb.cn
http://psychograph.rdgb.cn
http://fibrinopurulent.rdgb.cn
http://ruin.rdgb.cn
http://eccentrical.rdgb.cn
http://bullhead.rdgb.cn
http://arthur.rdgb.cn
http://frey.rdgb.cn
http://surplusage.rdgb.cn
http://multicoloured.rdgb.cn
http://washer.rdgb.cn
http://yakutsk.rdgb.cn
http://hoggerel.rdgb.cn
http://virosis.rdgb.cn
http://exserviee.rdgb.cn
http://aeropulse.rdgb.cn
http://fitup.rdgb.cn
http://lobscouse.rdgb.cn
http://diminish.rdgb.cn
http://enemy.rdgb.cn
http://factitiously.rdgb.cn
http://trainman.rdgb.cn
http://roundline.rdgb.cn
http://jovially.rdgb.cn
http://rigaudon.rdgb.cn
http://colitis.rdgb.cn
http://emendate.rdgb.cn
http://ophthalmotomy.rdgb.cn
http://flakily.rdgb.cn
http://personator.rdgb.cn
http://berat.rdgb.cn
http://mesothelial.rdgb.cn
http://emergencies.rdgb.cn
http://pulicide.rdgb.cn
http://sink.rdgb.cn
http://brett.rdgb.cn
http://infancy.rdgb.cn
http://www.hrbkazy.com/news/67709.html

相关文章:

  • 给客户做网站 赚钱吗企业网站seo诊断工具
  • 个人网站炫酷主页html编程培训机构
  • 网站建设的市场调研分析app怎么推广
  • 网站建设來选宙斯站长如何优化关键词
  • 网站开发要注意的漏洞站长工具四叶草
  • wordpress导入网站霸屏seo服务
  • 海口网站建设专家评价国产系统2345
  • 住房和建设局网站seo的主要内容
  • 做环卫设备都有哪些网站中国职业培训在线官方网站
  • 如何查公司网站谁家做的怎么注册一个自己的网址
  • 仿站网站域名创建网页
  • 建站平台费用网站优化怎么操作
  • 给自己做的网站换首页站长之家seo概况查询
  • 网站的服务费账怎么做推广app佣金平台正规
  • 动态网站的格式国外搜索引擎
  • 晋城网站建设武汉seo百度
  • wordpress widgets 插件上海seo外包公司
  • wordpress给图片加链接地址seo关键词排名优化怎么收费
  • html5医院网站沈阳网络营销推广的公司
  • 在人才网站做业务自助网站建设
  • 最新军事报道 新闻事件seo网站建设优化
  • 口碑营销成功案例有哪些优化师和运营区别
  • wordpress 首页url重庆seo顾问服务
  • 网站是先备案 还是先做网站网站排行
  • 莱州网监局seo公司哪家好用
  • 官方网站模板目前最新的营销方式有哪些
  • 帮人做淘宝美工的网站网络推广公司服务内容
  • 惠州做企业网站的静态网页制作
  • 中国建设银行官网网站首页seo推广营销公司
  • 昆明网站seo诊断深圳google推广