Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Compiler gives error of missing ']' while it's already there.

Reply
Thread Tools

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

 
 
vasudevmukherjee@yahoo.co.uk
Guest
Posts: n/a
 
      10-25-2005
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[i]=rand();
printf("%d\n", a[i]);
}
}

 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      10-25-2005
In article < om>,
<> wrote:

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


This expands to int a[9;];

-- Richard
 
Reply With Quote
 
 
 
 
Lew Pitcher
Guest
Posts: n/a
 
      10-25-2005
-----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)

iD8DBQFDXiKWagVFX4UWr64RAlvbAKDVhYzgX4bEujnIb7R4FY 4tnGmxtQCfalcR
VdLxzmKhtCWh405pQStf18s=
=8DSt
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      10-25-2005
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gem list --remote --details gives "ERROR: While executing gem ...(NoMethodError)" Markus Fischer Ruby 4 03-27-2011 12:59 PM
compiler gives me error message " boost/smart_ptr.h: No such file ordirectory" Pallav singh C++ 4 04-29-2009 08:01 AM
Compiler Error Message: The compiler failed with error code -1073741819 Ram ASP .Net 0 09-13-2005 09:52 AM
Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error JavaQueries Java 1 03-01-2005 06:30 PM
Compiler Error Message: The compiler failed with error code 128. Yan ASP .Net 0 07-21-2003 10:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57