Silly simple thing but...

BlitzMax Forums/BlitzMax Beginners Area/Silly simple thing but...

Ian Thompson(Posted 2009) [#1]
Hi, this bit of pseudo kinda explains what Im after but I can't find the syntax(if it exists)...

type Tmyinttype:int
global x:Tmyinttype = 3


x would be of type integer.

I don't want to create a custom record or object, in the traditional sense(no using 'new')...


Warpy(Posted 2009) [#2]
Why do you want to do this? If you want to extend the int type, I'm afraid you can't do it directly because ints aren't objects in bmax.


Grey Alien(Posted 2009) [#3]
I had to wrap an Int into a type (as a field) once in order to use it with the collision layer (which only returns objects and I just needed an Int)


Gabriel(Posted 2009) [#4]
It's not clear to me what you're trying to do. Are you trying to define Tmyinttype as a new name which you can use instead of int but which will operate identically? Like a TypeDef in C++? There used to be a command called Alias which I think did that, but it's been removed so I can't test it.


Ian Thompson(Posted 2009) [#5]
Well I have to wrap a header, the header has types like this, TSoundEntity, TObjectHandle, etc... all are simple integers. These forms of 'user defined types' are used mainly for readability. So you can create an array of TSoundEntity for example. Actually most, if not all languages I have come across use the term 'User Defined Type' to cover this, as well as class definitions and record types... I am finding it quite a surprise to see its not covered in BlitzMax?

Well, if its not available, then there's nothing I can do... at least I can stop scratching my head! :D


Nate the Great(Posted 2009) [#6]
someone said this feature used to be available so maybe you could check out older product updates... maybe the very first one?


markcw(Posted 2009) [#7]
Can't it be done from c++?


ImaginaryHuman(Posted 2009) [#8]
The basic datatypes - int, byte, etc have to be compatible with CPU registers. CPU's don't know anything about custom types, they only work with basic numbers, or numbers interpreted as addresses/pointers. You wouldn't be able to store a custom type in the cpu, as such, and have the CPU understand that it represents an integer. That's why you have to wrap them in a type if you need to use them that way.


Ian Thompson(Posted 2009) [#9]
Um, the type I was discussing would be converted back to an integer by the preprocessor before the compiler even gets warm.

This is just a question of syntax, its a pretty standard thing that is easy for a compiler developer to implement.


Kurator(Posted 2009) [#10]
As said by Grey Alien, the only way to do it - is like in java - creat an Integer Type containing a single int field...

JavaDoc for Integer: "The Integer class wraps a value of the primitive type int in an object. An object of type Integer contains a single field whose type is int."

That what you have tried is a sort of C-Style Typedef, and thats not working in MAX


Warpy(Posted 2009) [#11]
Yet again, operator overloading would've saved the day!