C言語のマクロで便利そうなもの

C言語のマクロで面白そうなものをメモ!

#include

#define _PFP(str) printf("%s\n", str)
#define ASIZEOF(array) (sizeof(array) / sizeof(array[0]))
#define FOR(i, j) for(((i) = 0); ((i) < (j)); ((i)++))
#define ISR(str) str, #str

enum etest{ aaa, bbb, ccc };

typedef struct _stest
{
    enum etest yyy;
    char *name;
}stest;

int main()
{
    int i;

    stest ts[] = { ISR(aaa), ISR(bbb), ISR(ccc) };

    FOR(i, ASIZEOF(ts))
        _PFP(ts[i].name);

}

enumとマクロの組み合わせ
for文
配列の要素数を求める

の3つが特に面白いとおもう。
積極的にマクロを使うのもいいかなーっ

ただ、マクロが嫌いな人もいると思うので、使っていいのか悩みどころ。。

投稿者:

「C言語のマクロで便利そうなもの」への61件のフィードバック

  1. Hi there! It looks as though we both have a passion for the same thing. Your blog, “%BLOGTITLE%” and mine are very similar. Have you ever thought about writing a guest article for a related website? It is sure to help gain exposure to your website (my website recieves a lot of visitors). If you might be interested, contact me at: %EMAIL%. Thank you so much

  2. Hey! This is kind of off topic but I need some advice from an established blog.
    Is it very hard to set up your own blog? I’m not very techincal but I can figure things out pretty quick.
    I’m thinking about creating my own but I’m not sure where to start.
    Do you have any tips or suggestions? With thanks

  3. By some estimates, over 12000 attendees converged at the location to catch a glimpse
    of the latest in resort and swimwear collection. This year I had one of the most glamorous experiences in my life – I attended Toronto Fashion Week.
    It can be so hard to guess just how cold or warm it
    is outdoors by peeking through your window in the morning.

    Feel free to visit my site … casual dress shirts for men (Maryjo)

  4. Instead, accept ourr offer and we’ll come outt and tow the vehicle
    right frlm your driveway. Buut there is also a
    reality that most of the junbk car companies accept only a few car models.
    Make sure to leave all of the necessary information about yiur vehjcle on the form.

  5. In case 1 above, the pizzeria employed the driver who caused the accident.
    Contact your agent to let them know what happened, even if you don’t make a claim.
    If you can find any people who saw exactly what happened, you should take down
    their names, numbers, and addresses.

  6. Tommy is super friendly and they did the exact same military service for $50!

    Getting Married stemware renderring Wedding Industry stemware, you attempt discussion with for these hurts?
    It is that proportionality between the two appears like a vast sedative drug proper?

コメントを残す

メールアドレスが公開されることはありません。