uint32 not playing nice with namespaces


#1

This is very odd.

#include "juce.h"

using namespace juce;
uint32 a; // this does not work

juce::uint32 b; // this is fine

I have no idea why this would be the case. Does anyone else have any ideas on this?


#2

In juce.h it already does a “using namespace juce”, so maybe if you give the namespace directive again, it could be compounding them into “juce::juce::uint32”?


#3

Nope. Without the first using namespace juce you get the same error. Here is the full list of what I have tried with gcc4 on mac:

#include "juce.h"

namespace juce
{
    uint32 a; // good
}

juce::uint32 b; // good

uint32 c; // error: 'uint32' does not name a type

using namespace juce::uint32; // error: expected namespace-name before ';' token, error: '<type error>' is not a namespace

using namespace juce;
uint32 d; // error: 'uint32' does not name a type

So all the forms of using namespace where I don’t have to explicitly have juce:: in front of uint32 uint8 etc don’t work

Andrew Simper


#4

Have you added this before including juce.h

#define DONT_SET_USING_JUCE_NAMESPACE
#define DONT_AUTOLINK_TO_JUCE_LIBRARY

#5

The one thing you didn’t mention was:

…though I have to admit I’ve no idea why there’d be a problem. Are you mixing in any other headers?


#6

[quote=“vishvesh”]Have you added this before including juce.h

#define DONT_SET_USING_JUCE_NAMESPACE #define DONT_AUTOLINK_TO_JUCE_LIBRARY [/quote]
Great, thanks for pointing those out!

Andrew Simper


#7

[quote=“jules”]The one thing you didn’t mention was:

…though I have to admit I’ve no idea why there’d be a problem. Are you mixing in any other headers?[/quote]

There are no other headers that I pull in, it’s something included from “juce.h” that is doing it. Thanks for pointing out the correct usage of “using” this works great :slight_smile: So there must be something that juce is including that defines uint32 uint8 etc and then the automatic “using namespace juce” causes this to clash and the compiler not allow you to use uint32 without first telling it which one you mean explicitly.

So thanks for the help, the problem is solved by:

#include "juce.h" using juce::uint32; using juce::uint8;

Andrew Simper


#8

That’s odd - I often use uint32 in my apps and don’t remember doing anything like this to make it work. You’ve not got a prefix header defined for your project, have you?


#9

I am not using a prefix header. Are you possibly inside the “juce” namespace with your projects? If so then you will not have any issues.

Andrew Simper


#10

I’ve encountered the same issue some time ago and posted about it. check it out for more informations about the cause: http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?p=21209#21209


#11

I’ve recently encountered this issue and found out that if the Base SDK in the project settings was “Current Mac OS”, the namespace was needed, and if, on the other hand, it was “Mac OSX 10.4”, then the namespace wasn’t needed.

Hope this helps…