c newbie, compiling problem

Started by
12 comments, last by 3flares 21 years, 8 months ago
This degree of programming malpractice is why globals are not recommended.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Advertisement
quote:Original post by Sneftel
Ahh, interesting: gcc allows redefinition of global variables. I wasn''t aware of this; I''ve been spending most of my time developing programs that need to compile across various platforms (in particular, SGI''s braindead C-compiler), and some of these architectures require the explicit extern-declaration.


Don''t take his words like that... the man was wrong and missunderstanding something. mabe he is declaring these variables in a header but for the link.exe to work properly this header must have been included only in one of the source files!

still use the extern keyword. its the right way as was mentioned before.

____________________________________MSN | AIM | YIM | ICQ
Aarg, I''m constantly mis-quoted! What I am trying to show is that a specific compiler (gcc) doesn''t give any errors or any kind of warning whatsoever when globals from separate files are used without an extern keyword. I''m NOT saying that it isn''t a good idea to use extern (you must if you''re following ANSI programming standards), NOR am I recommending that everyone drop using it. Once again, all I''m trying to say is that 3flares'' original error is NOT due to lack of the extern keyword. Sheesh.

And to those of you who seem to assume that not extern-ing those globals just won''t work (Sabreman and Cyberdrek): why the heck to you think I''ve gotten away with it for so long using one of the most popular, continually-updated compilers, and not noticed anything wrong?

Twilight Dragon
Win32 API Programmer
www.freewebz.com/j-world
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
The goal is to remain as compliant to standards as possible, whether or not you have to. While it may work in GCC, it won't very well with other compilers/linkers.

I'm not saying you don't know what your doing (hosestly, I haven't used GCC before so I have to take your word that it works), but just that it's a good idea to remain as portable as you can.

[edited by - Zipster on August 16, 2002 6:36:29 PM]

This topic is closed to new replies.

Advertisement