Register | Login
Forum Index > Bugs and Fixes > sizeof Array[]
Author Message
Pages: 1
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1537] sizeof Array[] - posted: 2015-01-29 14:34:17
Code:
program RAW_IMAGE 'test';

#set bits 32;

dword arr[] = [0, 1, 2, 3, 4, 5, 6, 7];
$echo sizeof arr;
The code above gets only 4.
Also is it possible to use $echo like print()? For example:
Code:
$echo 'Size = ', sizeof arr;
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1539] - posted: 2015-01-29 16:23:26
I think it may be worth to write a separate macro for such case... e.g. inline procedure echof .....

I may write one today to add to new rtl.

As for size of, I will correct this.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1554] - posted: 2015-01-30 16:44:00
OK, corrected sizeof and I have added a new macro $echof.

Code:
$echof('Hello World ', 123, ' etc!');


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1570] - posted: 2015-01-31 13:33:34
Don't know is it right or not:
Code:
program RAW_IMAGE 'test';

#set bits 32;

const s1 = '123456';

byte s2 [] = '123456';
byte s3 [] = s1;

$echof 'sizeof s1 = ', sizeof s1;
$echof 'sizeof s2 = ', sizeof s2;
$echof 'sizeof s3 = ', sizeof s3;

Result:
Code:
sizeof s1 = 7
sizeof s2 = 6
sizeof s3 = 6


Seems that zero-byte also was added to s1. But not in s3.
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1573] - posted: 2015-01-31 13:48:20
Yes, consts add null byte, but arrays just use the data which was written in the string, adding null byte is users option.

Edit: I have added string special char x for next release.

e.g.

Code:
byte s2 [] = '123456\x0';


Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
0CodErr
Ziron Guru
(send private message)

Posts: 199
Topics: 37

Location:
[1578] - posted: 2015-02-01 09:59:56
Another way -- use #define instead of const. But result the same. It strange smile
Code:
#define s1 '123456';

byte s2 [] = '123456';
byte s3 [] = s1;

And for example NASM version:
Code:
%define s1 '123456';

s2 db '123456';
s3 db s1;

Result: Code:
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36
Admin
Site Admin

avatar

(send private message)

Posts: 933
Topics: 55

Location:
OverHertz Studio
[1584] - posted: 2015-02-02 12:48:06
This is still normal behaviour, when assigning any string to an array, the null byte is not included unless you explicitly add it.

Download Ziron
Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.
Pages: 1
create new reply


Quick reply:

Message:



Currently Active Users:
There are currently 1 user(s) online. 0 member(s) and 1 guest(s)
Most users ever online was 1046, January 28, 2022, 2:08 pm.


Statistics:
Threads: 225 | Posts: 1848 | Members: 51 | Active Members: 51
Welcome to our newest member, yecate
const Copyright = '2011-2024 © OverHertz Ltd. All rights reserved.';
Web development by OverHertz Ltd