Compiler gives error of missing ']' while it's already there.

Discussion in 'C Programming' started by vasudevmukherjee@yahoo.co.uk, Oct 25, 2005.

  1. Guest

    Hi! Anybody there who can answer me on my following code:

    When I try to compile this code, I get message of a missing ']' on the
    line 3 i.e. int a[MAX];, why is this happening

    Thanks in anticipation.


    VASUDEV MUKHERJEE


    #include <stdio.h>
    #define MAX 9;
    int a[MAX];
    int rands=9;
    int rand()
    {
    rands=rands*1103515245 +12345;
    return (unsigned int) (rands/65536)%32768;
    }
    main ()
    {
    int i,t,x,y;
    for(i=0; i<MAX;i++)
    {
    a=rand();
    printf("%d\n", a);
    }
    }
    , Oct 25, 2005
    #1
    1. Advertising

  2. In article <>,
    <> wrote:

    >#define MAX 9;
    >int a[MAX];


    This expands to int a[9;];

    -- Richard
    Richard Tobin, Oct 25, 2005
    #2
    1. Advertising

  3. Lew Pitcher Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    wrote:
    > Hi! Anybody there who can answer me on my following code:
    >
    > When I try to compile this code, I get message of a missing ']' on the
    > line 3 i.e. int a[MAX];, why is this happening
    >
    > Thanks in anticipation.
    >
    >
    > VASUDEV MUKHERJEE
    >
    >
    > #include <stdio.h>
    > #define MAX 9;


    Think of the implication of the above macro when it is used in the line
    below

    > int a[MAX];


    Because of your #define for MAX, the above line will expand to
    int a[9;];
    before being parsed

    Is this what you intend? Is this legal C? (I know the answers - this is
    a hint to you that you should look into the questions a bit)

    [snip]

    - --

    Lew Pitcher, IT Specialist, Enterprise Data Systems
    Enterprise Technology Solutions, TD Bank Financial Group

    (Opinions expressed here are my own, not my employer's)
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (MingW32)

    iD8DBQFDXiKWagVFX4UWr64RAlvbAKDVhYzgX4bEujnIb7R4FY4tnGmxtQCfalcR
    VdLxzmKhtCWh405pQStf18s=
    =8DSt
    -----END PGP SIGNATURE-----
    Lew Pitcher, Oct 25, 2005
    #3
  4. wrote:
    > Hi! Anybody there who can answer me on my following code:
    >
    > When I try to compile this code, I get message of a missing ']' on the
    > line 3 i.e. int a[MAX];, why is this happening


    > #include <stdio.h>
    > #define MAX 9;
    > int a[MAX];


    This expands to
    int a[ 9; ];
    the error of which is clearer, I think, when written
    int a[9;
    ];
    Fix it by losing the semicolon from the #define.
    Martin Ambuhl, Oct 25, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yan
    Replies:
    0
    Views:
    1,133
  2. JavaQueries
    Replies:
    1
    Views:
    3,659
    John C. Bollinger
    Mar 1, 2005
  3. Pallav singh
    Replies:
    4
    Views:
    1,184
    James Kanze
    Apr 29, 2009
  4. Merciadri Luca
    Replies:
    5
    Views:
    1,088
    Merciadri Luca
    Oct 14, 2010
  5. Markus Fischer
    Replies:
    4
    Views:
    347
    Nick Klauer
    Mar 27, 2011
Loading...

Share This Page