如何仅从__date__宏中提取年份 [英] How to extract year alone from the __date__ macro

查看:421
本文介绍了如何仅从__date__宏中提取年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I want to just take the year part from __date__ macro, so as to make a macro which contains a string like

这样一来,我就可以为项目(VS 2013)中的各种.rc文件提供此CYC宏,该文件本身就是一个GUI.项目

So that I can supply  this  CYC macro  for various .rc files in my project (VS 2013) , which itself is a GUI project

但是,一旦我尝试了这一点,我所得到的就是与宏扩展有关的一堆错误

But once I attempted this, all I got are a bunch of errors related to macro expansion

我尝试了以下不同方法:

I have tried  different approaches as below :

#define COPY "Copyright"

#define COMPANY "ABCD Lmtd"

Method #1

[ 7

#define BUILD_YEAR_CH0 (__DATE__[ 7])

#define BUILD_YEAR_CH1 (__DATE__[8])

#define BUILD_YEAR_CH2 (__DATE__[9])

#define BUILD_YEAR_CH3 (__DATE__[10])

BUILD_YEAR_CH3

#define CYC BUILD_YEAR_CH0 BUILD_YEAR_CH1 BUILD_YEAR_CH2 BUILD_YEAR_CH3 COMPANY

Method #2 /* I tried this method just out of curiosity, I don't want to replace my macro with a variable. */

const YEAR =

const char YEAR[] = { __DATE__[7], __DATE__[8],__DATE__[9],__DATE__[10],'\0' };

#define YEAR COPY YEAR COMPANY

方法#3.

#define xstr(s)str(s)

#define xstr(s) str(s)

#define str(s)s

#define str(s) #s

#define年份__date__ +7

#define年份COPY xstr(MYEAR)COMPANY

#define YEAR COPY xstr(MYEAR) COMPANY

方法3没有给出任何预处理器错误,但输出为: Copyright("Jan 30 2017" + 7)ABCD Lmtd,当然这不是我的意图

Method #3 is not giving any pre-processor error, but the output is : Copyright("Jan 30 2017" + 7)ABCD Lmtd, which is certainly not my intention

真的仅使用宏而不使用任何变量来完成此简单任务是真的吗?

Is it really impossible to accomplish this simple task only with macros, not using any variables ?

推荐答案

如果您需要此文件版本资源-尝试 这个在构建后的步骤中.不要浪费时间使用所有这些define和rc文件.

If you need this for a file version resource - try this  in the post-build step. Don't waste time with all these defines and rc files.

-pa


这篇关于如何仅从__date__宏中提取年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆