Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33

Thread: How to make all-files-global variable?

  1. #21
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make all-files-global variable?

    I was referring to Qt because this is a forum which talks about Qt as the main point of interest

    Anyway, enough off-topic, hopefully the OP now has what he wants.

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make all-files-global variable?

    Quote Originally Posted by Timoteo View Post
    Do you know the "extern" keyword from asm? Sorry, but I couldn't resist. Know your roots, people!
    My roots is Atari BASIC, there is no "extern" keyword there
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #23
    Join Date
    Sep 2010
    Posts
    145
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make all-files-global variable?

    Hah, my BASIC was the Commodore flavor. How old are you?

    Atari had a cartridge based assembler didn't it? Crazy stuff.

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make all-files-global variable?

    Quote Originally Posted by Timoteo View Post
    How old are you?
    Old enough. I started programming when I was around 9 yo.

    Atari had a cartridge based assembler didn't it?
    Cartridge is just a storage device so I guess this is not some important feature of it. I remember one could do assembly directly from BASIC by providing some weird blocks of numbers. At the time I didn't understand any of it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #25
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to make all-files-global variable?

    The C64 used a cartridge-based asssembler. Their cartridge was a read-only expansion device, more often used to ship games, but in this case it gave you an editor and an actual assembly language implementation so you could program using HLL tokens which the assembler then converted into machine code.

    The first C64 program I wrote in assembler was a rewrite of a Commodore Basic version of the mathematical game "Life". It ran over a thousand times faster than it's interpreted cousin.

  6. #26
    Join Date
    Sep 2010
    Posts
    145
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make all-files-global variable?

    Man, I was like..10 i think at the time...and I didn't have access to anything but a VIC-20 and the tape deck and some programming magazines. It is weird that I remember (wrongly) Atari having a cartridge assembler and not the C64. Did the VIC-20 have it also? I feel really deprived now.

  7. #27
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make all-files-global variable?

    I just checked in wikipedia. Earlier versions of Atari had BASIC provided on a cartridge while later ones (like my Atari 65 XE) had it built-in into ROM. Nothing about assembly though.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #28
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make all-files-global variable?

    The C64 cartridge based assembler was the red 'Power cartridge' guess ? Then you could also use your function keys to show a directory listing without overwriting your program (as you would do with "load *,8,1" if I remember correctly). Great tool.

    Regards,
    Marc
    P.S. I was 13 at the time

  9. #29
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make all-files-global variable?

    I remember writing machine level code for the VIC-20 and C64 using DATA statements along with POKE commands. I had to write all the assembler on scrapes of paper, manually convert it into numbers for the DATA statements, and then watch it crash when I run it.

    My first assembler was for the Commodore Amiga, called ASM-One (freeware) and then changed to DevPac (commercial).

    Sheesh, I feel like I'm showing my age

  10. #30
    Join Date
    Sep 2010
    Posts
    145
    Thanks
    1
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make all-files-global variable?

    Ahh, don't feel bad. Yes, I remember PEEK and POKE and flipping through the programming magazines to find the encoding for "cool looking" sprites. Graph paper was a must if you were sketching out your own.

  11. #31
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make all-files-global variable?

    Quote Originally Posted by squidge View Post
    I remember writing machine level code for the VIC-20 and C64 using DATA statements along with POKE commands. I had to write all the assembler on scrapes of paper, manually convert it into numbers for the DATA statements, and then watch it crash when I run it.
    That's the part I didn't understand at the time.

    My first assembler was for the Commodore Amiga, called ASM-One (freeware)
    Been there, done that. I remember trying to battle with the Intuition library to be able to open a window or something
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #32
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make all-files-global variable?

    I remember playing with the builtin libraries and coming up with the verdict that the libraries were far too slow for what I wanted to do. I then got a copy of the Amiga hardware reference manual and had much more fun. I'm sure most Amiga nuts will remember bouncing copper bars, which was always the first hardware hackers demo, followed by spinning 3D floppy disks and the like, those always seemed to be the first demos by people getting into assembler development. I also remember writing a track loader as I wasn't impressed with the standard OS disk routines (and the famous 0×4489 disk sync).

  13. #33
    Join Date
    Nov 2010
    Posts
    97
    Thanks
    6
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to make all-files-global variable?

    Quote Originally Posted by hakermania View Post
    Ok, I just thought than in 2010 somebody would have though about variables than can be used everywhere and can be created in a simple way....
    Anyway, I'll have a try at the singleton. Thanx both
    This being 2010, many decades of studying design techniques and measuring the success of the projects that use them...people have pretty much universally decided that global variables are to be avoided at nearly all cost.

    Actually, people knew this a long time ago. Most people discover it on their own if they don't learn from those ahead of them in the field.

    You might have a case for using one. I'd probably look for a different way but I'm not working on your project so...wtf do I know. At any rate, there's no reason to go through the incredibly expensive effort of altering a language for something like this. Declaring and defining global variables is already fairly easy, though it could be admitted that someone brand new could find it unintuitive.

    I followed the link you were given, didn't see what you need to know there. Here's how to do it:

    In a header file:
    Qt Code:
    1. extern type my_var;
    To copy to clipboard, switch view to plain text mode 

    This is a declaration.

    In ONE .cpp file:
    Qt Code:
    1. type my_var = a_value;
    To copy to clipboard, switch view to plain text mode 

    This is a definition AND an initialization. I suggest initializing your variable, but if you don't it will be "default initialized" (set to 0 in case of an int). You could also initialize through a function call, and in fact I use this a LOT for factory registration (a bigger topic). Just remember that anything you use to initialize your variable will happen before main is called and you have *absolutely no way of knowing in which order* except within specific cpp files.

    Once you've done the above two things you can use that variable anywhere that includes the .h you declared it in.

    Technically you don't have to have a header, but the reasons behind that would just confuse the hell out of you. Just do it this way...if you really must use a global variable.
    This rude guy who doesn't want you to answer his questions.

    Note: An "expert" here is just someone that's posted a lot.

    "The fact of where you do the encapsulation is meaningless." - Qt Certified Developer and forum moderator

Similar Threads

  1. Replies: 2
    Last Post: 21st October 2010, 07:03
  2. global variable in QT: getting ISSUES
    By Girija in forum Qt Programming
    Replies: 8
    Last Post: 19th September 2010, 16:15
  3. Setting a global variable
    By Windsoarer in forum Qt Programming
    Replies: 3
    Last Post: 16th February 2010, 22:37
  4. how to declare a global variable right
    By Cruz in forum Newbie
    Replies: 13
    Last Post: 16th February 2010, 16:25
  5. global variable
    By Shuchi Agrawal in forum General Programming
    Replies: 10
    Last Post: 15th February 2007, 04:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.