LoginSignup
5
5

More than 5 years have passed since last update.

C言語でRubyのeachっぽいものを書いてみる

Posted at

備忘録。
この手の記事は多いみたいだけれど、自分でも作成してみた。

each_sample.c
#include <stdio.h>

#define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0]))
#define EACH(array,type,obj) for(type* obj=array;obj<=&array[ARRAYSIZE(array)-1];obj++)

long array[10];

int main()
{
    array[0] = 0;
    array[1] = 1;
    array[2] = 2;
    array[3] = 3;
    array[4] = 4;

    EACH(array,long,obj)
    {
        printf("%d\n", *obj);
    }
}

しっかりと作りこんであるのは、
ココ とか、
ここ にあり。

5
5
1

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