LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-16-2003, 02:25 PM   #1
fr0zen
Member
 
Registered: Nov 2003
Location: 127.0.0.1
Distribution: xubuntu
Posts: 217

Rep: Reputation: 30
Global Code Organization


I've been searching for documentation, tutorial, some kind of information regarding proper (well, "nice") means of organizing code within separate files, etc. More specifically, namespace usage. I know how to create a namespace

Code:
namespace vsf {
// code
}
But, what I have is something more like the following:

Code:
namespace vsf {
 namespace api {
   // api specific code, functions, variables
 }
 namespace gdi {
   // gdi...
 }
}
I see this as an easy way to prevent name clashes, not to mention organization. The problem is this file is going to get big after a while (big project). So, why not split it up? I want to first have each 'inner' namespace in its own .h file, defined (all variables and functions), and then an implementation file for each inner namespace that initializes the variables and specifies the function bodies.

I'm not saying I haven't tried to do this. I've tried several times. Each time it ends up with me getting several hundred errors. Usually 'unresolved symbol' or 'duplicate definition', or something to that effect.

Last edited by fr0zen; 12-16-2003 at 02:31 PM.
 
Old 12-16-2003, 02:39 PM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
If you are going to put global variables in the header file, you should use the "extern" keyword and then put the actual implementation of those global variables into a source file. And don't forget the pre-compiler guards!

Example:
Code:
// Header
#ifndef _SOME_HEADER_H_
#define _SOME_HEADER_H_

extern int g_nValue;
#endif

// Source file
#include "someheader.h"

int g_nValue = 0;

Last edited by deiussum; 12-16-2003 at 02:40 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM
New distro for new organization HILLbilly General 4 08-20-2004 02:56 PM
Folder Organization kam1su2 Slackware - Installation 3 04-22-2004 06:46 AM
System organization help sulzla Linux - Newbie 2 06-28-2003 07:03 PM
organization... ixion Linux - Software 1 04-01-2003 02:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration