There can be an array and a scalar with the same name

by qbguy (no login)

> DIM i(20) AS INTEGER
> PRINT LEN(i)

> The output is 4. I might have found a bug in QB as a result of that little
> bit of code too. After all, the size of an INTEGER is 2, not 4. In the
> above code, 'i' is treated as a SINGLE. Putting a DEFDBL A-Z at the very
> top confirms this by outputting 8. It happens in QB 4.5 and PDS (7.1)

It is referring to the variable i, not the array i. Since undeclared variables are of type SINGLE, it prints 4, which is the size of a SINGLE. I don't think LEN was intended to work for arrays -- the docs say any nonstring variable -- so it would seem that it means a normal variable, not an array. Note that LEN does work for derived types (user-defined types):

TYPE coord
x AS SINGLE
y AS SINGLE
END TYPE
DIM p AS coord
PRINT LEN(p)

prints 8.


In C, sizeof seems to return the size of the array in bytes:
#include <stdio.h>

int main(int argc, char *argv[])
{
char array1[10]; /*array of 10 char*/
short array2[20]; /* array ot 10 16-bit integers */
printf("%d\n", sizeof(array1));
printf("%d\n", sizeof(array2));
return 0;
}

Posted on Apr 16, 2008, 3:17 PM
from IP address 76.216.72.56

Respond to this message   

Return to Index


Response TitleAuthor and Date
* Really? That annoys me a lot!rpgfan3233 on Apr 16