need help with extern pointers.

This is a discussion on need help with extern pointers. within the C Programming forums, part of the General Programming Boards category; Make a struct, stuff all the common arguments in there and pass it around. Unless there's a real need for ...

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,022
    Make a struct, stuff all the common arguments in there and pass it around. Unless there's a real need for global variables, I'd avoid it.
    There are things that need global variables, but this isn't it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Just bear in mind that if you are actually interested in performance within your ray-tracer, using local variables or parameters is likely to produce better code, since the compiler must assume that global variables may be affected by any function call you make (except for functions that the compiler decides to inline and thus can decide that this portion of code doesn't modify certain variables).

    It does sound like those definitions are suitable for storing in a struct that is passed as one const pointer to all functions (that need them).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,849
    If you absolutely must use globals, then a few rules will help matters.

    1. Use a decent namespace, like prefixing all globals with "g_". If you use something terse like 'obj', then you're going to have surprises. One unfortunate project from my past managed to make a global variable called 'i'. Talk about chaos.

    2. Put them all in one place, so that you can instantly see the scope of the problem should you ever want to port the code somewhere else.

    3. Use gcc and compile with the -Wshadow option, to tell you about the case you highlighted in this thread, namely having a global and a parameter with the same name. But naming rules will also help.

    4. Keep the numbers down. Less than 10 is a lot easier to manage than say more than 100.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 05:25 AM
  2. Extern Question, really confused
    By SourceCode in forum C Programming
    Replies: 10
    Last Post: 03-26-2003, 11:11 PM
  3. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM
  4. extern symbols, what do these mean exactly?
    By Shadow12345 in forum C++ Programming
    Replies: 8
    Last Post: 11-02-2002, 03:14 PM
  5. extern keyword and structures
    By GuitGentlyWeeps in forum C Programming
    Replies: 2
    Last Post: 01-30-2002, 07:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21