and it will break a bit the compatibility with old PB sources, but this is not big problem.
In general, when there is required a variable type as parameter for built-in functions you can make with dot as prefix.
A good reason why SizeOf() refuses simple types?
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re:
ohhh!Fred wrote:A good idea IHMO. It will break the compatibility with the normal 'C like' SizeOf() so I will see what can be done.
Still nothing done
Code: Select all
Structure localevar
a.w
b.f
c.l
EndStructure
Procedure func()
Protected localevar.b=4
Debug SizeOf(localevar) ; <- ?? 10 ?? , damn lie!, SizeOf(localevar) value is 1, not 10
EndProcedure
func()
Re: A good reason why SizeOf() refuses simple types?
Yeah, I'm with Psycho (that sounds sooooooo wrong). It just makes sense (and I seem to recall it's the same way ol' Gfa did it, though that's not a recommendation, I know
)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Re: Re:
That struct rquires 10 bytes, so why would it return 1? A pointer would be either 4 or 8, so even if you are looking for a pointer to a struct, would still not return 1.Psychophanta wrote:ohhh!Fred wrote:A good idea IHMO. It will break the compatibility with the normal 'C like' SizeOf() so I will see what can be done.
Still nothing done![]()
Code: Select all
Structure localevar a.w b.f c.l EndStructure Procedure func() Protected localevar.b=4 Debug SizeOf(localevar) ; <- ?? 10 ?? , damn lie!, SizeOf(localevar) value is 1, not 10 EndProcedure func()
Re: A good reason why SizeOf() refuses simple types?
he has defined (protected) a variable with the same name as structure but with the type Byte.
but the help say:
but the help say:
and I think that should stay that way.Note: if a variable and a structure have the same name, the structure will have the priority over the variable.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: A good reason why SizeOf() refuses simple types?
Much more simple:
Gives 2 as result 
Code: Select all
word.l
Debug SizeOf(word)
-
BorisTheOld
- Enthusiast

- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: A good reason why SizeOf() refuses simple types?
All other BASIC languages that I've used treat data types as reserved words. Therefore, "w", "i", "q", etc, would not be allowed for the names of variables. And since structure names are used as data types, they too are treated as reserved words and are not allowed as variable names.
On the other hand, PB is like other BASICs, in that SizeOf will work with structure names but not with the built-in data types.
Although quirky, PB's rules are clear. So using built-in constants for the length of data types would be the correct thing to do.
However, although allowed, using data type names and structure names for variable names, is a bad, bad, bad!!! idea. As are single letter variable names.
On the other hand, PB is like other BASICs, in that SizeOf will work with structure names but not with the built-in data types.
Although quirky, PB's rules are clear. So using built-in constants for the length of data types would be the correct thing to do.
However, although allowed, using data type names and structure names for variable names, is a bad, bad, bad!!! idea. As are single letter variable names.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
~ Spike Milligan

