views:

248

answers:

2

Hi,

I know this is really basic, but its got me stumped...

In Objective-C I'm trying to write:

const int BUF_SIZE = 3;

static char buffer[BUF_SIZE+1];

But I get a storage size of buffer isn't constant. How do I make Xcode realise that I'm setting it to a constant, + 1...? Or is this not possible...?

Thanks...!

Joel

+3  A: 

I think it's a C thing—if I recall correctly, C only allows you to specify array sizes with literal expressions (no symbols whatsoever). I'd just use a #define constant as a workaround.

htw
Thanks – I'd completely forgotten about #DEFINE... J
Joel B
+1  A: 

You can use an enum:

enum
{
    BUF_SIZE = 3
};

Or a macro

#define BUF_SIZE 3
dreamlax