Author Topic: type alias  (Read 3414 times)

0 Members and 1 Guest are viewing this topic.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
type alias
« on: March 29, 2019, 02:13:59 pm »
is there a way to declare a type alias?
like TYPE REAL AS DOUBLE
DIM X AS REAL would be the same as DIM X AS DOUBLE

FellippeHeitor

  • Guest
Re: type alias
« Reply #1 on: March 29, 2019, 02:19:35 pm »
Nope.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: type alias
« Reply #2 on: March 29, 2019, 02:27:09 pm »
thanks for the reply FellippeHeitor

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: type alias
« Reply #3 on: March 29, 2019, 02:46:45 pm »
Sorry I don't agree

you can respecting the TYPE syntax lke showed here http://qb64.org/wiki/TYPE and adoptin the dot as your second best friend.
Code: QB64: [Select]
  1. TYPE  real
  2.  
  3. DIM c AS DOUBLE, Argh AS REAL
  4. LET c = SQR (3)
  5. LET Argh.a = c
  6. PRINT " Double ";c; " Real ";Argh.a
  7.  
  8.  

Thanks for reading
Programming isn't difficult, only it's  consuming time and coffee

Offline freetrav

  • Newbie
  • Posts: 45
    • View Profile
Re: type alias
« Reply #4 on: March 29, 2019, 03:39:53 pm »
The problem with @TempodiBasic's "solution" is that it dishonors the querent's intent. While it may work from a 'machine' point of view - that is, the structure REAL defined by the TYPE may look in memory to be identical to a DOUBLE - it does not preserve the syntax that the querent was suggesting.

QB64 does not seem to have a preprocessor the way that most C compilers do (although the underlying C compilation may have one), but if it did, types could be aliased with (for example) #DEFINE REAL DOUBLE

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: type alias
« Reply #5 on: March 30, 2019, 05:28:30 am »
@Freetrav
let me explain my previous response

1. I agree with you that my solution is more a provocation that uses a workaround to arrive where the querent claims to go  than an effective solution.

2. taking a more general case in that the coder wants to DUPLICATE the keyword of  a fundamental TYPE of data of the language:
 from my little point of experience and point of view I cannot imagine in what the BASIC (a Procedural Language of Programming ) can be empowered by this kind of performance (duplication of the token keyword that the human uses to write code and the parser uses to translate the code for compiler).
Surely this my affirmation doesn't mean that jack's question is an error.

3. about preprocessor: fantastic idea! I seem to remember  for  RapidQ the community built a preprocessor to manage more extentions of the language that the same community brought on over in the time. It can be an idea for new clever programmers to create a new utility for QB64 like  vWatch, InForm, GM64, those of Ashis, Unseen, David, RhoSigma and so more others that now I don't remember (sorry for an unwanted exclusion).
Programming isn't difficult, only it's  consuming time and coffee