3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Visual C++で#warningを作った

Last updated at Posted at 2019-08-10

コンパイル時に意図的にWarningを出したい

Visual Studioのお話。
C#だと#warningがあって意図的に警告を出せるのですが、C++には無いので作りました。

実装

# define STRING2(x) #x
# define STRING(x) STRING2(x)
# define SetWarning( x ) __pragma( message (__FILE__ "(" STRING(__LINE__) "):warning:" x ) )

使い方

SetWarning( "エッッッッッッッッツ" )

コンパイル出力

image.png

VS2019以前ではエラー一覧に出て来ませんでしたが、
VS2019では表示されるようになってました。完璧です。
image.png

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?