Home AMX User Forum AMX Technical Discussion

Silly question about arrays

I'm having a little issue with a couple of devices not responding...well, one doesn't respond and the other does sometimes, but sometimes doesn't. I've found, in the code, that I made a mistake:
The code in the NI4100 currently has:
VOLATILE CHAR cBrightsignIPAddress[1][15]= '192.168.200.27'
instead of:
VOLATILE CHAR cBrightsignIPAddress[1][15]= { '192.168.200.27' }

Now I reckon that this is why the Brightsign is not responding (when referenced by cBrightsignIPAddress[1]). What I can't figure out is why Netlinx would accept the first version without warning or error, and what it is actually compiling it as. Only thing I can think of is that referring to cBrightsignIPAddress[1] will result in '1', i.e. the first character. Or are the two statements above identical, as far as Netlinx is concerned?

(OK, I know that it should be empty in the first square brackets instead of [1])

As for the other device only responding sometimes, I figured it could be because the next line defines the arrays for the IP addresses of two similar devices...but the device is accessed via RS422 (so I'm not sure why the IP addresses are listed - but I didn't write the code, I'm just modifying it). I think the answer here could be a hardware issue (e.g. I wired up the cable incorrectly).

Comments

  • KielLKielL Posts: 29

    I was curious what the answer was, so I compiled both statements and examined their contents in debugger. It looks like both end up as an array with one string element, 14 characters in length:

    No idea why the Brightsign isn't responding, sorry!

  • Hmmm...interesting. Thank you.

    I have seen, and written, IF statements without the braces (and done the same thing in Delphi without the begin...end statements). Not the thing to do, of course, according to the style guide. So I wonder if this is the same thing - braces only required when more than one element.

    I'm sure the Brightsign problem is a silly typo somewhere that I've missed, as it works fine with the test program on the test controller, so I must have copied it across wrong.

  • The IP address here is just a string (single dimensional character array) so:

    VOLATILE CHAR cBrightsignIPAddress[] = '192.168.200.27'

    will work fine. You reference it by just using 'cBrightsignIPAddress', without referencing any dimension. If you use 'cBrightsignIPAddress[1]', you will only get '1', the first character, as you already mentioned.

    For the initialization statement for a single dimension character array you use single quotes, you only use braces for non char types (like integers, longs, etc.) and multidimensional char arrays.

    VOLATILE CHAR cName[ ] = 'character string'
    VOLATILE INTEGER nName[ ] = {1, 2, 3}

    VOLATILE CHAR cName[2][17]={{ 'character string1'}, { 'character string2'}}

    Now, I don't know WHY it is this way, just is... :|

Sign In or Register to comment.