Typedef and returns

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
legider_pb
User
User
Posts: 39
Joined: Tue Nov 25, 2003 12:28 pm

Typedef and returns

Post by legider_pb »

It would be nice to have typedef AND be able to return said type. For example I create a structure:

Code: Select all

Structure CustomerInfo
    ID.l
    Name.s
    Email.s
EndStructure

TYPEDEF Customer AS CustomerInfo

Procedure.Customer DisplayInfo(Current.Customer)
    Debug Current\ID
    Debug Current\Name
    Debug Current\Email
    
    NewCustomer.Customer
    NewCustomer\ID = 25
    NewCustomer\Name = "Bob"
    NewCustomer\Email = "Bob@Bob.com"

    ProcedureReturn NewCustomer
EndProcedure

Customer1.Customer
Customer1\ID = 15
Customer1\Name = "Frank"
Customer1\Email = "Frank@Frank.com"

Customer2.Customer = DisplayInfo(Customer1)
Well that about sums it up, I know this is possible in a manner of speaking using some API calls and such, but I believe for cross platform things which I am aiming for, this would be immensely useful.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

what's the purpose of that ?
wht not simply as usual write

var.struct ?

I just ask, i don't say it's useless :)
- Registered PB user -

Using PB 4.00
legider_pb
User
User
Posts: 39
Joined: Tue Nov 25, 2003 12:28 pm

Post by legider_pb »

It's useful because you can define a type that works like a string or a long, but is actually a structure. Which means passing it to functions and returning them from functions easier. It also makes your code easier to organize, maybe this is just my C++ background talking.

Yes in a slight manner of speaking this can be done with pointers, but it is ugly if you ask me
Post Reply