home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] Programming Question re: namespace ??

* William Case <billlinux [ at ] rogers [ dot ] com> [070820 10:22]:
> Hi;
> 
> I have several paragraphs of notes regarding the 'namespace' concept.
> Those notes, however, leave some ambiguity. (Trying to cast the widest
> possible net to capture all possibilities  -- I suspect.)  I don't need
> a full explanation of what a namespace is other than to confirm which of
> the following possibilities could be called a 'namespace'.
> 
> If I write the 'bills_program' in C and then call it, is a 'namespace'

First, C doesn't have namespaces.  C++ does.

>      I. bills_program
>     II. main()
>    III. function() -- within main

Avoid defining private functions inside other functions.  I am not sure
if that's what you mean here.  But GCC extensions let you do this:

int main (void)
{
        int function (int b) {
                return a * 2;
        }

        ...
}

>     IV. each of the above
>      V. more
>     VI. something else

A namespace in C++ can put code into logical groups:

namespace bill {
        
        class Foo {
                Foo (void);

                ...
        }
}

you would now address the class as bill.Foo.

The best you can do in C is to use a prefix on your non-static functions
and data.

in bill.c ...

        int bill_public_data = 0;

        int bill_public_function (int a)
        {
                ...
        }

in bill.h ...

        extern int bill_public_data;
        extern int bill_public_function(int a);

> I understand 'namespace' as an abstraction that is used as a root idea
> for memory allocations or use, which is subdivided into various other
> cancepts (eg text, bbs, stack, stack frame etc.) depending on the
> organization of a called program.

C++ namespaces have nothing to do with that.

> While I am at it.  When a program is called, how does the processor know
> how much memory to allocate for that program. Is it one page at a time,
> one process at a time or does the compiler put a size number in the file
> header, or what ?

Processor doesn't know.

The operating system will load up the data from disk into ram as it's
used.  For example glibc is huge.  No program uses all of it.  If no one
is interested in a particular 4k of glibc, it's never loaded into
memory.

Memory is allocated based on the elf header.  


> Please just point me, I am willing to read.

man elf
man readelf

-Bart

-- 
				WebSig: http://www.jukie.net/~bart/sig/