Initialising variables

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.

I thought it was always possible to do this:

age
name$

to declare those variables (they generate a compiler error, although e.g. foo.w works OK)? Am I mistaken or has this changed?



--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.50)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

I don't think so... how can the compiler know if "age" is meant to be
a variable, as opposed to a mistyped command? I think it's always
been required to append .l, .s, .w, etc to a variable declaration.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.
Originally posted by PB

I don't think so... how can the compiler know if "age" is meant to be
a variable, as opposed to a mistyped command? I think it's always
been required to append .l, .s, .w, etc to a variable declaration.
Gidday.

I made that mistake one before so I went throught my code and then read the manual (usually I read the manual first, shame on me).

Somewhere in there it says that PB compiler regards all variables as integers (I think that was the syntax) unless specifically declared otherwise with a type.

I looked through my code and saw lots of variables with no type and the compiler never generated an error so I assume the manual was right for once :):)


Fangles woz ear orright den?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> Somewhere in there it says that PB compiler regards all variables
> as integers (I think that was the syntax) unless specifically
> declared otherwise with a type.

Yes, this is true for numeric variables -- the compiler considers
them to be of long (not integer) type, if undeclared. BUT, that
said, you can't declare a variable by name alone like Tinman said
in his original post. You still have to use age.l and not age.

This has been true since at least v2.40 (I just checked it). :)
Post Reply