C코드 “[0 … 255] =” 에서 ...은 뭘까요?

조회수 2562회

소스 코드

    static void *gostruct[] =
    {
        [0 ... 255] = &&l_bad,
        ['\t'] = &&l_loop, [' '] = &&l_loop, ['\r'] = &&l_loop, ['\n'] = &&l_loop,
        ['"'] = &&l_qup,
        [':'] = &&l_loop, [','] = &&l_loop,
        ['['] = &&l_up, [']'] = &&l_down, // tracking [] and {} individually would allow fuller validation but is really messy
        ['{'] = &&l_up, ['}'] = &&l_down,
        ['-'] = &&l_bare, [48 ... 57] = &&l_bare, // 0-9
        [65 ... 90] = &&l_bare, // A-Z
        [97 ... 122] = &&l_bare // a-z
    };

........
.......

l_bad:
    *vlen = cur - json; // where error'd
    return 0;

........
........

출처 : [여기]

이 코드에서 "..." 이랑 "&&l_bad"는 뭘까요? 점같은건 검색도 안되고 답답합니다..

1 답변

  • 좋아요

    0

    싫어요
    채택 취소하기

    ...는 GCC에서 제공하는 extension으로 특정 범위를 같은 값으로 초기화할 때 씁니다.

    Designated Initializers를 보면

    To initialize a range of elements to the same value, write [first ... last] = value. This is a GNU extension. For example,

    int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };

    &&도 extension으로, 함수 내에있는 라벨의 주소를 알아낼 때 씁니다(binary op 논리 AND랑은 다름) Labels as Values를 보면

    You can get the address of a label defined in the current function (or a containing function) with the unary operator &&. The value has type void *. This value is a constant and can be used wherever a constant of that type is valid. For example:

    void *ptr;
    /* ... */
    ptr = &&foo;
    

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)