Aha!
"(for example, allowing you to set or test it)" you mean like a redim?
But I wonder why the first dimension is starting with one and not zero...
Compare struct speed vs array - is it a fair way to compare?
-
- Posts: 127
- Joined: Tue 07 May 2019, 16:47
Re: Compare struct speed vs array - is it a fair way to compare?
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
-
- Posts: 127
- Joined: Tue 07 May 2019, 16:47
Re: Compare struct speed vs array - is it a fair way to compare?
I expected that counting from 0 to 9 or 0 to F or whatever number system, was most the most used way in programming. But when Sophie had decided to count from one I won't dare to argue against her.
Can you explain in pedagogical terms the advance of using one instead of zero?
Maybe it's also Sophie had decided that TRUE = -1 and not 1?
Can you explain in pedagogical terms the advance of using one instead of zero?
Maybe it's also Sophie had decided that TRUE = -1 and not 1?
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
Re: Compare struct speed vs array - is it a fair way to compare?
I'm not an expert in that field. All I can say, from a practical perspective, is that index zero is often used to refer to something 'special' rather than the 'first' item in the list. For example, it might contain the count of the number of items, or it might contain something else relevant to the entire list (e.g. a title or a description). If I have a list of files in an array, commonly I put the path to the directory at index zero and the first filename at index 1.
The way BBC BASIC's arrays work can also lead you to treat index zero as a special case, since DIM array(n%) dimensions an array with n%+1 elements (indices running from 0 to n% inclusive). This is different from some BASICs, and effectively gives you an 'extra' element array(0) in addition to the 'expected' array(1) to array(n%).
That's easier to explain. It's because BBC BASIC (unlike C for example) does not distinguish between a Boolean inversion (! in C) and a binary inversion (~ in C). In BBC BASIC the NOT function serves both purposes, so since FALSE is 0, TRUE must be NOT FALSE which is -1.Maybe it's also Sophie had decided that TRUE = -1 and not 1?
-
- Posts: 127
- Joined: Tue 07 May 2019, 16:47
Re: Compare struct speed vs array - is it a fair way to compare?
"BBC BASIC (unlike C for example) does not distinguish between a Boolean inversion"
a = 1
b = -1
IF a PRINT "a is true"
IF b PRINT "b is true"
IF a AND b PRINT "a and b are true"
If I understand correct will all above be true...
"If I have a list of files in an array, commonly I put the path to the directory at index zero and the first filename at index 1."
I think its good to have some rules for different task - that simplifies or reduce errors in my code.
Its meaningful BBC Basic uses min_x_pos,min_y_pos = 0,0 for text and graphics.
a = 1
b = -1
IF a PRINT "a is true"
IF b PRINT "b is true"
IF a AND b PRINT "a and b are true"
If I understand correct will all above be true...
"If I have a list of files in an array, commonly I put the path to the directory at index zero and the first filename at index 1."
I think its good to have some rules for different task - that simplifies or reduce errors in my code.
Its meaningful BBC Basic uses min_x_pos,min_y_pos = 0,0 for text and graphics.
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
Re: Compare struct speed vs array - is it a fair way to compare?
Yes, but do be careful not to confuse 'true' (which you are using here to mean that the IF statement succeeds) and TRUE (which is the unique value -1)!
Neither BBC BASIC nor C has a Boolean data type, they both use integers to stand in for Booleans, so whereas a Boolean only has two possible values an integer has 2^32 possible values. FALSE is one of those values, TRUE is another, but that leaves 2^32-2 values unaccounted for. It is important to realise that the IF statement (and all other conditional tests) will consider those other 2^32-2 values as 'true' even though they aren't TRUE.
So, to summarise, although BBC BASIC and C differ in the value they use for TRUE (-1 in the former case, +1 in the latter) they are identical in respect of how the IF statement and other conditional tests work: any non-zero value causes the test to succeed.
-
- Posts: 127
- Joined: Tue 07 May 2019, 16:47
Re: Compare struct speed vs array - is it a fair way to compare?
Thanks for clearing that misunderstanding.
a = -1
IF a = TRUE PRINT "a is true"
a = -1
IF a = TRUE PRINT "a is true"
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.