Thread: global variables - okay sometimes...?

  1. #16
    Could we have the source?

  2. #17
    Evil Sock Puppet MadHatter's Avatar
    Join Date
    Nov 2002
    Posts
    176
    >Could we have the source?

    heh.. not in it's current state i'll have to clean it up some, and maybe comment it a bit... i'm just finishing up the scoring and everything, so i'll try to post it later today.

    //edit: source is up.. you can get it from that thread where people post their best games (in the gaming forum)
    Last edited by MadHatter; 01-05-2003 at 08:09 PM.
    If I had a world of my own, everything would be nonsense. Nothing would be what it is, because everything would be what it isn't. And contrariwise, what it is, it wouldn't be, and what it wouldn't be, it would. You see?

  3. #18
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Heh... My class version right now only has a ball and is ASCII (don't know graphics and don't really have the time to learn... college starts again in about a week).

    As for globals... it uses them for the screen's size and for the ASCII character that represents the ball (I'm using #define ).

  4. #19
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by Frobozz
    (I'm using #define ).
    Why not use const?
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  5. #20
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Good question... I'm just using it because I've seen it used a lot in a friend's code and also in my professor's code (even though I haven't taken his class yet).

    Is const better? Does #declare allow stuff to be used regardless of data type?
    Last edited by Frobozz; 01-07-2003 at 01:21 AM.

  6. #21
    Registered User
    Join Date
    Apr 2002
    Posts
    110
    when you use #define such as in the form
    #define PI 3.1415926
    then PI will be treated as though it is a float.
    PI could also be declared as
    const float PI = 3.1415926

    Not much difference, though one is a const global variable the other is a #define statement

    Later,
    WebmasterMattD
    WebmasterMattD.NET

  7. #22
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by WebmasterMattD
    when you use #define such as in the form
    #define PI 3.1415926
    then PI will be treated as though it is a float.
    PI could also be declared as
    const float PI = 3.1415926

    Not much difference, though one is a const global variable the other is a #define statement

    Later,
    Actually, it would be a double, not a float.

    #define doesn't obey scope rules, so you shouldn't use it much. There are only very few places you should have to use #define, and this is not one of them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global variables.
    By vapanchamukhi in forum C Programming
    Replies: 5
    Last Post: 09-15-2008, 05:02 AM
  2. Replies: 5
    Last Post: 08-06-2008, 09:59 AM
  3. scope of global variables
    By laertius in forum C++ Programming
    Replies: 4
    Last Post: 10-15-2006, 01:59 AM
  4. global variables
    By rdnjr in forum Linux Programming
    Replies: 0
    Last Post: 01-07-2003, 10:28 AM
  5. Global variables? Bad! Yes, but to what extent?
    By Boksha in forum C++ Programming
    Replies: 6
    Last Post: 05-26-2002, 04:37 PM