A good reason why SizeOf() refuses simple types?

Everything else that doesn't fall into one of the other PB categories.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

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.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re:

Post by Psychophanta »

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.
ohhh!
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()
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: A good reason why SizeOf() refuses simple types?

Post by blueznl »

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... )
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Re:

Post by Tenaja »

Psychophanta wrote:
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.
ohhh!
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()
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.
User avatar
STARGÅTE
Addict
Addict
Posts: 2315
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: A good reason why SizeOf() refuses simple types?

Post by STARGÅTE »

he has defined (protected) a variable with the same name as structure but with the type Byte.

but the help say:
Note: if a variable and a structure have the same name, the structure will have the priority over the variable.
and I think that should stay that way.
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 moreTypeface - Sprite-based font include/module
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: A good reason why SizeOf() refuses simple types?

Post by Psychophanta »

Much more simple:

Code: Select all

word.l
Debug SizeOf(word)
Gives 2 as result :shock:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: A good reason why SizeOf() refuses simple types?

Post by BorisTheOld »

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.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
Post Reply