Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   What's wrong with this code: arrays? (http://www.go4expert.com/forums/whats-wrong-code-arrays-t8015/)

gormster 28Dec2007 07:44

What's wrong with this code: arrays?

- (void) sendMessage:(int) type data:(char[]) data length:(int)length
        char message[length];
        message[0] = type;

I know this is in Obj-C but the important part is pure C. The weird bit at the top is just Obj-C's way of making an instance method. Basically, length and type are both integers.

So, I pass 0x90 to 'type', and the printf gives me FFFFFF90. If I printf message[1] or [2], I get 7 and FFFFFF84, respectively. They should, of course, be empty.

So, what the hell is going on? I feel I have made some kind of rookie mistake.

gormster 28Dec2007 07:46

Re: What's wrong with this code: arrays?
PS: I should mention that if I replace the message[0] = type with message[0] = 0x90, it works fine.

All times are GMT +5.5. The time now is 10:50.