8
7

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 5 years have passed since last update.

HEREマクロ

Posted at

デバッグなど出力をするときに使うと便利なマクロです。

heremacro.h
#define _STR(x)      #x
#define _STR2(x)     _STR(x)
#define __SLINE__    _STR2(__LINE__)
#define HERE         __FILE__  ":" __SLINE__ " "

使い方はこんな感じ

main.c
#include <stdio.h>
#include "heremacro.h"
int main() {
    printf(HERE "hello world\n");
    return 0;
}

出力結果はこうなる。

main.c:4 hello world

__FUNC__マクロとかを使ってカスタマイズするもよし。
元ネタはこちら http://d.hatena.ne.jp/mindcat/20090523/1243045233

8
7
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
8
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?