473,837 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Globals from a namespace

I know this sounds nasty, but let me explain.
I have what was a class that contains a whole buncha function pointers
(for OpenGL extensions) that are used in the app. I was porting this
app to macs, where the extensions are properly present (just normal
functions) so the class is not needed. I was wanting a way to make
the same code work on both. For example, if I could do this:
glGenBuffersARB (bla); on both. On the mac its just accessing the
OpenGL function, on the Windows machine it would have a using
namespace whatever; at the top and is actually accessing those
function pointers of the same name.

This seemed like it would work fine for my purposes, but I can't seem
to get the namespace pointers to be truly shared across the app. It
seems like every function that wants to use them has to assign them
itself.

Right now it looks like this (this isn't a copy paste [hopefully
obviously] just an example):
namespace whatever
{
static PtrType func1;
static PtrType2 func2;
// etc

InitPointers(); // defined in cpp; assignes all the function pointers
with wglGetProcAddre ss
};
Any ideas to make this work without having to do a whole lot of #ifdef
WIN32 #else's in the code?

Mar 6 '07 #1
5 1860
jg*******@gmail .com wrote:
I know this sounds nasty, but let me explain.
I have what was a class that contains a whole buncha function pointers
(for OpenGL extensions) that are used in the app. I was porting this
app to macs, where the extensions are properly present (just normal
functions) so the class is not needed. I was wanting a way to make
the same code work on both. For example, if I could do this:
glGenBuffersARB (bla); on both. On the mac its just accessing the
OpenGL function, on the Windows machine it would have a using
namespace whatever; at the top and is actually accessing those
function pointers of the same name.

This seemed like it would work fine for my purposes, but I can't seem
to get the namespace pointers to be truly shared across the app. It
seems like every function that wants to use them has to assign them
itself.

Right now it looks like this (this isn't a copy paste [hopefully
obviously] just an example):
namespace whatever
{
static PtrType func1;
static PtrType2 func2;
// etc
Why 'static'? What if you drop 'static'? If you have this in the
header, you need to add 'extern'. Then in one of the C++ modules
you need to actually initialise them with something (NULL should be
fine), and then make 'InitPointers() ' be called from another object's
initialisation:

int dummy = (InitPointer(), 42);
>
InitPointers(); // defined in cpp; assignes all the function pointers
with wglGetProcAddre ss
};
Any ideas to make this work without having to do a whole lot of #ifdef
WIN32 #else's in the code?
See above.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 6 '07 #2
jg*******@gmail .com wrote:
I know this sounds nasty, but let me explain.
I have what was a class that contains a whole buncha function pointers
(for OpenGL extensions) that are used in the app. I was porting this
app to macs, where the extensions are properly present (just normal
functions) so the class is not needed. I was wanting a way to make
the same code work on both. For example, if I could do this:
glGenBuffersARB (bla); on both. On the mac its just accessing the
OpenGL function, on the Windows machine it would have a using
namespace whatever; at the top and is actually accessing those
function pointers of the same name.

This seemed like it would work fine for my purposes, but I can't seem
to get the namespace pointers to be truly shared across the app. It
seems like every function that wants to use them has to assign them
itself.

Right now it looks like this (this isn't a copy paste [hopefully
obviously] just an example):
namespace whatever
{
static PtrType func1;
static PtrType2 func2;
Why are those static? That means every translation unit that wants to use
them needs its own set of pointers. Maybe that's where your problem is
coming from?
// etc

InitPointers(); // defined in cpp; assignes all the function pointers
with wglGetProcAddre ss
};
Any ideas to make this work without having to do a whole lot of #ifdef
WIN32 #else's in the code?

Mar 6 '07 #3
Victor Bazarov wrote:
jg*******@gmail .com wrote:
>I know this sounds nasty, but let me explain.
I have what was a class that contains a whole buncha function pointers
(for OpenGL extensions) that are used in the app. I was porting this
app to macs, where the extensions are properly present (just normal
functions) so the class is not needed. I was wanting a way to make
the same code work on both. For example, if I could do this:
glGenBuffersAR B(bla); on both. On the mac its just accessing the
OpenGL function, on the Windows machine it would have a using
namespace whatever; at the top and is actually accessing those
function pointers of the same name.

This seemed like it would work fine for my purposes, but I can't seem
to get the namespace pointers to be truly shared across the app. It
seems like every function that wants to

Right now it looks like this (this isn't a copy paste [hopefully
obviously] just an example):
namespace whatever
{
static PtrType func1;
static PtrType2 func2;
// etc

Why 'static'? What if you drop 'static'? If you have this in the
header, you need to add 'extern'. Then in one of the C++ modules
you need to actually initialise them with something (NULL should be
fine),
Globals are automatically initialized (to zero in case of PODs).
and then make 'InitPointers() ' be called from another object's
initialisation:

int dummy = (InitPointer(), 42);
I'm not sure that's possible in this case. The function might itself need
some initialization of the OpenGL before, and I'm not sure if that is safe
before main().

Mar 6 '07 #4
>>
>>Right now it looks like this (this isn't a copy paste [hopefully
obviously] just an example):
namespace whatever
{
static PtrType func1;
static PtrType2 func2;


Why are those static? That means every translation unit that wants to use
them needs its own set of pointers. Maybe that's where your problem is
coming from?
I would guess because originally 'whatever' was a class, which at some
point got changed to a namespace.

john
Mar 6 '07 #5
extern fixed it, thank you! I was unaware of this (probably
obviously).
By the way, I did require explicitly initializing them in a CPP file
to prevent linker errors in response to those mentioning it.

Thanks a lot guys!

- Justin

Victor Bazarov wrote:
jg*******@gmail .com wrote:
I know this sounds nasty, but let me explain.
I have what was a class that contains a whole buncha function pointers
(for OpenGL extensions) that are used in the app. I was porting this
app to macs, where the extensions are properly present (just normal
functions) so the class is not needed. I was wanting a way to make
the same code work on both. For example, if I could do this:
glGenBuffersARB (bla); on both. On the mac its just accessing the
OpenGL function, on the Windows machine it would have a using
namespace whatever; at the top and is actually accessing those
function pointers of the same name.

This seemed like it would work fine for my purposes, but I can't seem
to get the namespace pointers to be truly shared across the app. It
seems like every function that wants to use them has to assign them
itself.

Right now it looks like this (this isn't a copy paste [hopefully
obviously] just an example):
namespace whatever
{
static PtrType func1;
static PtrType2 func2;
// etc

Why 'static'? What if you drop 'static'? If you have this in the
header, you need to add 'extern'. Then in one of the C++ modules
you need to actually initialise them with something (NULL should be
fine), and then make 'InitPointers() ' be called from another object's
initialisation:

int dummy = (InitPointer(), 42);

InitPointers(); // defined in cpp; assignes all the function pointers
with wglGetProcAddre ss
};
Any ideas to make this work without having to do a whole lot of #ifdef
WIN32 #else's in the code?

See above.

V
Mar 7 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4326
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would be better to promote better programming than rely on PHP to compensate for lazy programming?
3
2081
by: Robert Dodier | last post by:
Hello, I'm interested in introducing new variables into the environment of a Python interpreter or program. In reading through old posts to this newsgroup, I see there is an often-repeating warning against modifying the contents of locals(). Fair enough. However, is there anything wrong with modifying globals() ?
2
4190
by: tedsuzman | last post by:
----- def f(): ret = 2 exec "ret += 10" return ret print f() ----- The above prints '12', as expected. However,
45
2698
by: It's me | last post by:
I am new to the Python language. How do I do something like this: I know that a = 3 y = "a" print eval(y)
0
1136
by: Geert Jansen | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I'm experiencing a weird problem with eval(), providing it a copy of the globals() dictionary. The following code works:
18
2953
by: robert | last post by:
Using global variables in Python often raises chaos. Other languages use a clear prefix for globals. * you forget to declare a global * or you declare a global too much or in conflict * you have a local identical variable name and want to save/load it to/from the global with same name * while you add code, the definition of globals moves more and more apart from their use cases -> weirdness; programmers thinking is fragmented * using...
5
1300
by: Steven W. Orr | last post by:
I have two seperate modules doing factory stuff which each have the similar function2: In the ds101 module, def DS101CLASS(mname,data): cname = mname+'DS101' msg_class = globals() msg = msg_class(data) return msg
1
1859
by: cokofreedom | last post by:
if __name__ == '__main__': print "Globals (For Loop):" try: for i in globals(): print "\t%s" % i except RuntimeError: print "Only some globals() printed\n" else: print "All globals() printed\n"
0
1049
by: Gabriel Genellina | last post by:
En Sat, 12 Jul 2008 16:15:36 -0300, Akathorn Greyhat <akathorn@gmail.com> escribi�: Welcome! You have to pass in the namespace of the desired module - instead of globals. I'd use an explicit argument:
7
5557
by: CapnBearbossa | last post by:
hi all, forgive me , but the RTFM and Google search approaches are not yielding an answer on this question. I need to know if there's a top level python interpreter command that clears all user variables (not built-ins) from the global namespace. In other words a statement, or some_command_or_function(), that does this:
0
9830
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9682
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10864
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10562
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7803
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6989
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5664
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4469
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.