前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >#define的一个小技巧

#define的一个小技巧

作者头像
用户4645519
发布2020-09-08 10:09:03
3180
发布2020-09-08 10:09:03
举报
文章被收录于专栏:嵌入式学习嵌入式学习
代码语言:javascript
复制
/* atof example: sine calculator */
#include <stdio.h>      /* printf, fgets */
#include <stdlib.h>     /* atof */
#include <math.h>       /* sin */



#define vfd_com_timeout_clear()     do{vfd_com_cnt = 0;}while(0)
#define vfd_com_timeout_recount()   do{vfd_com_cnt = 0;}while(0)

/*
判断等待时间是否超时
*/
int is_eload_com_timeout(void)
{
    //电子负载超过2s时间尚未反馈
    if (1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}


int main ()
{
    double n, m;
    double pi = 3.1415926535;
    char buffer[256] = {"000000.01212\n234"};

    int vfd_com_cnt = 5;
    printf("vfd_com_cnt = %d\n",vfd_com_cnt);
    vfd_com_timeout_clear();
    printf("vfd_com_cnt = %d\n",vfd_com_cnt);

    if (!is_eload_com_timeout())
    {
		printf("oooo\n");
    }
	else
	{
		printf("kkkkk\n");
	}
	

    n = atof (buffer);
    printf("n=%f\n", n);
    m = sin (n * pi / 180);
    printf ("The sine of %f degrees is %f\n", n, m);
    return 0;
}

int is_eload_com_timeout(void)
{

    if (1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}


int main ()
{
    double n, m;
    double pi = 3.1415926535;
    char buffer[256] = {"000000.01212\n234"};

    int vfd_com_cnt = 5;
    printf("vfd_com_cnt = %d\n",vfd_com_cnt);
    do{vfd_com_cnt = 0;}while(0);
    printf("vfd_com_cnt = %d\n",vfd_com_cnt);

    if (!is_eload_com_timeout())
    {
  printf("oooo\n");
    }
 else
 {
  printf("kkkkk\n");
 }


    n = atof (buffer);
    printf("n=%f\n", n);
    m = sin (n * pi / 180);
    printf ("The sine of %f degrees is %f\n", n, m);
    return 0;
}

上文已经就将源代码和预编译后的比分文字合作一起了。

#define vfd_com_timeout_clear() do{vfd_com_cnt = 0;}while(0)

这个代码我起初以为会有问题,应为括号里面是空的,

但是使用gcc -E .\atofc.c -o atofc.i后,发现直接替换了,因此该方法可以使用。

但是注意,宏定义不检查语法的,因此写宏定义的时候要格外小心。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-10-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档