"struct Mem" conflicts with namespaces/classes having the same name

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
17 messages Options
dip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

"struct Mem" conflicts with namespaces/classes having the same name

dip
I downloaded latest SQLite Amalgamation (v 3.18.0) to embed it in my project.
After that I got a lot of errors while compiling (compiler is Microsoft Visual Studio 2017).
Errors were caused by the following line in sqlite3.h:

typedef struct Mem sqlite3_value;

The reason is that I have the namespace with the same name.
So I have a suggestion to rename "struct Mem" to something else (add prefix to it) because "Mem" is a very common name like "input" or "data" or "buffer" and there may be classes or namespaces having the same name.

Sent with [ProtonMail](https://protonmail.com) Secure Email.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Olivier Mascia

> Le 9 avr. 2017 à 18:49, dip <[hidden email]> a écrit :
>
> I downloaded latest SQLite Amalgamation (v 3.18.0) to embed it in my project.
> After that I got a lot of errors while compiling (compiler is Microsoft Visual Studio 2017).
> Errors were caused by the following line in sqlite3.h:
>
> typedef struct Mem sqlite3_value;
>
> The reason is that I have the namespace with the same name.
> So I have a suggestion to rename "struct Mem" to something else (add prefix to it) because "Mem" is a very common name like "input" or "data" or "buffer" and there may be classes or namespaces having the same name.

The way to overcome this completely in large programmings using many libraries is to include sqlite3.h within a namespace. Not something that SQLite code must do itself: that's best handled at the user project level.

--
Best regards, Meilleures salutations, Met vriendelijke groeten,  
Olivier Mascia (from mobile device), http://integral.software

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Richard Damon
On 4/9/17 1:49 PM, Olivier Mascia wrote:

>> Le 9 avr. 2017 à 18:49, dip <[hidden email]> a écrit :
>>
>> I downloaded latest SQLite Amalgamation (v 3.18.0) to embed it in my project.
>> After that I got a lot of errors while compiling (compiler is Microsoft Visual Studio 2017).
>> Errors were caused by the following line in sqlite3.h:
>>
>> typedef struct Mem sqlite3_value;
>>
>> The reason is that I have the namespace with the same name.
>> So I have a suggestion to rename "struct Mem" to something else (add prefix to it) because "Mem" is a very common name like "input" or "data" or "buffer" and there may be classes or namespaces having the same name.
> The way to overcome this completely in large programmings using many libraries is to include sqlite3.h within a namespace. Not something that SQLite code must do itself: that's best handled at the user project level.
>
The problem with this is that if the header file is put in a namespace
in the user code, then the source file that defines these functions
needs to also be changed to put the files in that same namespace, or the
things being defined won't be found.

--
Richard Damon

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

J Decker
On Sun, Apr 9, 2017 at 12:20 PM, Richard Damon <[hidden email]>
wrote:

> On 4/9/17 1:49 PM, Olivier Mascia wrote:
>
>> Le 9 avr. 2017 à 18:49, dip <[hidden email]> a écrit :
>>>
>>> I downloaded latest SQLite Amalgamation (v 3.18.0) to embed it in my
>>> project.
>>> After that I got a lot of errors while compiling (compiler is Microsoft
>>> Visual Studio 2017).
>>> Errors were caused by the following line in sqlite3.h:
>>>
>>> typedef struct Mem sqlite3_value;
>>>
>>> The reason is that I have the namespace with the same name.
>>> So I have a suggestion to rename "struct Mem" to something else (add
>>> prefix to it) because "Mem" is a very common name like "input" or "data" or
>>> "buffer" and there may be classes or namespaces having the same name.
>>>
>> The way to overcome this completely in large programmings using many
>> libraries is to include sqlite3.h within a namespace. Not something that
>> SQLite code must do itself: that's best handled at the user project level.
>>
>> The problem with this is that if the header file is put in a namespace in
> the user code, then the source file that defines these functions needs to
> also be changed to put the files in that same namespace, or the things
> being defined won't be found.
>
> think that's what 'use namespace' is for


> --
> Richard Damon
>
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
dip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

dip
sqlite3.c is C file. C does not support namespaces.
Even though another project files are .cpp, sqlite3.c is still compiled as C language source.
Therefore, no ability to use "using namespace" in sqlite3.c.
Also, "using namespace" does not actually put functions in the source in namespace. It just helps it find another functions without specifying namespace name.

Sent with [ProtonMail](https://protonmail.com) Secure Email.

-------- Original Message --------
Subject: Re: [sqlite] "struct Mem" conflicts with namespaces/classes having the same name
Local Time: April 9, 2017 10:23 PM
UTC Time: April 9, 2017 7:23 PM
From: [hidden email]
To: SQLite mailing list <[hidden email]>

On Sun, Apr 9, 2017 at 12:20 PM, Richard Damon <[hidden email]>
wrote:

> On 4/9/17 1:49 PM, Olivier Mascia wrote:
>
>> Le 9 avr. 2017 à 18:49, dip <[hidden email]> a écrit :
>>>
>>> I downloaded latest SQLite Amalgamation (v 3.18.0) to embed it in my
>>> project.
>>> After that I got a lot of errors while compiling (compiler is Microsoft
>>> Visual Studio 2017).
>>> Errors were caused by the following line in sqlite3.h:
>>>
>>> typedef struct Mem sqlite3_value;
>>>
>>> The reason is that I have the namespace with the same name.
>>> So I have a suggestion to rename "struct Mem" to something else (add
>>> prefix to it) because "Mem" is a very common name like "input" or "data" or
>>> "buffer" and there may be classes or namespaces having the same name.
>>>
>> The way to overcome this completely in large programmings using many
>> libraries is to include sqlite3.h within a namespace. Not something that
>> SQLite code must do itself: that's best handled at the user project level.
>>
>> The problem with this is that if the header file is put in a namespace in
> the user code, then the source file that defines these functions needs to
> also be changed to put the files in that same namespace, or the things
> being defined won't be found.
>
> think that's what 'use namespace' is for

> --
> Richard Damon
>
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Bob Friesenhahn
On Sun, 9 Apr 2017, dip wrote:

> sqlite3.c is C file. C does not support namespaces.
> Even though another project files are .cpp, sqlite3.c is still compiled as C language source.
> Therefore, no ability to use "using namespace" in sqlite3.c.
> Also, "using namespace" does not actually put functions in the source in namespace. It just helps it find another functions without specifying namespace name.

Nevertheless, it is possible to include the C header file within a C++
namespace and then import the functions you need into the namespace
used by your own C++ code or refer to them specifically within the
namespace you created.  I have done this successfully across many C++
compilers for 19 years already.

It would definitely be best if sqlite does not pollute the name space
with names not starting from a common prefix.

Bob
--
Bob Friesenhahn
[hidden email], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
dip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

dip
What happens with mangling then? extern "C" functions inside a namespace just do not get mangled? If so, sounds like a workaround.

But it will be really better if SQLite adds prefix to it's "Mem" and other internals.

Sent with [ProtonMail](https://protonmail.com) Secure Email.

-------- Original Message --------
Subject: Re: [sqlite] "struct Mem" conflicts with namespaces/classes having the same name
Local Time: April 9, 2017 11:19 PM
UTC Time: April 9, 2017 8:19 PM
From: [hidden email]
To: SQLite mailing list <[hidden email]>

On Sun, 9 Apr 2017, dip wrote:

> sqlite3.c is C file. C does not support namespaces.
> Even though another project files are .cpp, sqlite3.c is still compiled as C language source.
> Therefore, no ability to use "using namespace" in sqlite3.c.
> Also, "using namespace" does not actually put functions in the source in namespace. It just helps it find another functions without specifying namespace name.

Nevertheless, it is possible to include the C header file within a C++
namespace and then import the functions you need into the namespace
used by your own C++ code or refer to them specifically within the
namespace you created. I have done this successfully across many C++
compilers for 19 years already.

It would definitely be best if sqlite does not pollute the name space
with names not starting from a common prefix.

Bob
--
Bob Friesenhahn
[hidden email], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Keith Medcalf
You mean like this:

https://www.sqlite.org/src/info/19dd753f9e50fee2


--
˙uʍop-ǝpısdn sı ɹoʇıuoɯ ɹnoʎ 'sıɥʇ pɐǝɹ uɐɔ noʎ ɟı

> -----Original Message-----
> From: sqlite-users [mailto:[hidden email]]
> On Behalf Of dip
> Sent: Sunday, 9 April, 2017 14:48
> To: SQLite mailing list <[hidden email]>
> Subject: Re: [sqlite] "struct Mem" conflicts with namespaces/classes
> having the same name
>
> What happens with mangling then? extern "C" functions inside a namespace
> just do not get mangled? If so, sounds like a workaround.
>
> But it will be really better if SQLite adds prefix to it's "Mem" and other
> internals.
>
> Sent with [ProtonMail](https://protonmail.com) Secure Email.
>
> -------- Original Message --------
> Subject: Re: [sqlite] "struct Mem" conflicts with namespaces/classes
> having the same name
> Local Time: April 9, 2017 11:19 PM
> UTC Time: April 9, 2017 8:19 PM
> From: [hidden email]
> To: SQLite mailing list <[hidden email]>
>
> On Sun, 9 Apr 2017, dip wrote:
>
> > sqlite3.c is C file. C does not support namespaces.
> > Even though another project files are .cpp, sqlite3.c is still compiled
> as C language source.
> > Therefore, no ability to use "using namespace" in sqlite3.c.
> > Also, "using namespace" does not actually put functions in the source in
> namespace. It just helps it find another functions without specifying
> namespace name.
>
> Nevertheless, it is possible to include the C header file within a C++
> namespace and then import the functions you need into the namespace
> used by your own C++ code or refer to them specifically within the
> namespace you created. I have done this successfully across many C++
> compilers for 19 years already.
>
> It would definitely be best if sqlite does not pollute the name space
> with names not starting from a common prefix.
>
> Bob
> --
> Bob Friesenhahn
> [hidden email], http://www.simplesystems.org/users/bfriesen/
> GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Bob Friesenhahn
In reply to this post by dip
On Sun, 9 Apr 2017, dip wrote:

> What happens with mangling then? extern "C" functions inside a namespace just do not get mangled? If so, sounds like a workaround.

Yes, extern "C" functions don't get mangled.

Bob
--
Bob Friesenhahn
[hidden email], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Daniel Anderson
In reply to this post by dip
I see no problems with C++.

Mem is only foward declared, you can redefined it to whatever you want. as
long as you do not redefined it for sqlite.c you should be good.

in sqlite.h it's declared:

struct Mem;

so in your code if you do:

struct Mem { int a;int b;} then your definition will be used for your code.

as sqlite is only using pointer, and has his own definition, I do not see
the problem.

it breaks the ODR, but as I previously said it's used/allocated internally
 by sqlite which should never see your definition.

can you explain in more detail what is happening ?

can you make a small reproduceable  sample ?

also are you mixing C++ & C, or is your code all in c ?

Daniel

2017-04-09 15:49 GMT-04:00 dip <[hidden email]>:

> sqlite3.c is C file. C does not support namespaces.
> Even though another project files are .cpp, sqlite3.c is still compiled as
> C language source.
> Therefore, no ability to use "using namespace" in sqlite3.c.
> Also, "using namespace" does not actually put functions in the source in
> namespace. It just helps it find another functions without specifying
> namespace name.
>
> Sent with [ProtonMail](https://protonmail.com) Secure Email.
>
> -------- Original Message --------
> Subject: Re: [sqlite] "struct Mem" conflicts with namespaces/classes
> having the same name
> Local Time: April 9, 2017 10:23 PM
> UTC Time: April 9, 2017 7:23 PM
> From: [hidden email]
> To: SQLite mailing list <[hidden email]>
>
> On Sun, Apr 9, 2017 at 12:20 PM, Richard Damon <[hidden email]>
> wrote:
>
> > On 4/9/17 1:49 PM, Olivier Mascia wrote:
> >
> >> Le 9 avr. 2017 à 18:49, dip <[hidden email]> a écrit :
> >>>
> >>> I downloaded latest SQLite Amalgamation (v 3.18.0) to embed it in my
> >>> project.
> >>> After that I got a lot of errors while compiling (compiler is Microsoft
> >>> Visual Studio 2017).
> >>> Errors were caused by the following line in sqlite3.h:
> >>>
> >>> typedef struct Mem sqlite3_value;
> >>>
> >>> The reason is that I have the namespace with the same name.
> >>> So I have a suggestion to rename "struct Mem" to something else (add
> >>> prefix to it) because "Mem" is a very common name like "input" or
> "data" or
> >>> "buffer" and there may be classes or namespaces having the same name.
> >>>
> >> The way to overcome this completely in large programmings using many
> >> libraries is to include sqlite3.h within a namespace. Not something that
> >> SQLite code must do itself: that's best handled at the user project
> level.
> >>
> >> The problem with this is that if the header file is put in a namespace
> in
> > the user code, then the source file that defines these functions needs to
> > also be changed to put the files in that same namespace, or the things
> > being defined won't be found.
> >
> > think that's what 'use namespace' is for
>
> > --
> > Richard Damon
> >
> >
> > _______________________________________________
> > sqlite-users mailing list
> > [hidden email]
> > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> >
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>



--
Daniel
*L'action accède à la perfection quand, bien que vivant, vous êtes déjà
mort*
*Bunan*
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
dip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

dip
I am mixing C and C++ code. My code is in C++, SQLite is in C.
Just create memory.h:

namespace Mem {
// some functions
}

And create code.cpp:

#include "memory.h"
#include "sqlite3.h"

void Func()
{
Mem::SomeFunc(); // gives the compilation error
}

Sent with [ProtonMail](https://protonmail.com) Secure Email.

-------- Original Message --------
Subject: Re: [sqlite] "struct Mem" conflicts with namespaces/classes having the same name
Local Time: April 10, 2017 2:29 AM
UTC Time: April 9, 2017 11:29 PM
From: [hidden email]
To: SQLite mailing list <[hidden email]>

I see no problems with C++.

Mem is only foward declared, you can redefined it to whatever you want. as
long as you do not redefined it for sqlite.c you should be good.

in sqlite.h it's declared:

struct Mem;

so in your code if you do:

struct Mem { int a;int b;} then your definition will be used for your code.

as sqlite is only using pointer, and has his own definition, I do not see
the problem.

it breaks the ODR, but as I previously said it's used/allocated internally
by sqlite which should never see your definition.

can you explain in more detail what is happening ?

can you make a small reproduceable sample ?

also are you mixing C++ & C, or is your code all in c ?

Daniel

2017-04-09 15:49 GMT-04:00 dip <[hidden email]>:

> sqlite3.c is C file. C does not support namespaces.
> Even though another project files are .cpp, sqlite3.c is still compiled as
> C language source.
> Therefore, no ability to use "using namespace" in sqlite3.c.
> Also, "using namespace" does not actually put functions in the source in
> namespace. It just helps it find another functions without specifying
> namespace name.
>
> Sent with [ProtonMail](https://protonmail.com) Secure Email.
>
> -------- Original Message --------
> Subject: Re: [sqlite] "struct Mem" conflicts with namespaces/classes
> having the same name
> Local Time: April 9, 2017 10:23 PM
> UTC Time: April 9, 2017 7:23 PM
> From: [hidden email]
> To: SQLite mailing list <[hidden email]>
>
> On Sun, Apr 9, 2017 at 12:20 PM, Richard Damon <[hidden email]>
> wrote:
>
> > On 4/9/17 1:49 PM, Olivier Mascia wrote:
> >
> >> Le 9 avr. 2017 à 18:49, dip <[hidden email]> a écrit :
> >>>
> >>> I downloaded latest SQLite Amalgamation (v 3.18.0) to embed it in my
> >>> project.
> >>> After that I got a lot of errors while compiling (compiler is Microsoft
> >>> Visual Studio 2017).
> >>> Errors were caused by the following line in sqlite3.h:
> >>>
> >>> typedef struct Mem sqlite3_value;
> >>>
> >>> The reason is that I have the namespace with the same name.
> >>> So I have a suggestion to rename "struct Mem" to something else (add
> >>> prefix to it) because "Mem" is a very common name like "input" or
> "data" or
> >>> "buffer" and there may be classes or namespaces having the same name.
> >>>
> >> The way to overcome this completely in large programmings using many
> >> libraries is to include sqlite3.h within a namespace. Not something that
> >> SQLite code must do itself: that's best handled at the user project
> level.
> >>
> >> The problem with this is that if the header file is put in a namespace
> in
> > the user code, then the source file that defines these functions needs to
> > also be changed to put the files in that same namespace, or the things
> > being defined won't be found.
> >
> > think that's what 'use namespace' is for
>
> > --
> > Richard Damon
> >
> >
> > _______________________________________________
> > sqlite-users mailing list
> > [hidden email]
> > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> >
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>

--
Daniel
*L'action accède à la perfection quand, bien que vivant, vous êtes déjà
mort*
*Bunan*
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Daniel Anderson
Ah, understood.

I thought you had a struct or a class named Mem.


then short term solution is to rename Mem in sqlite.h

using the #define directive + include file should do the trick.

as they say solve it by using a level of indirection!

It will be a bit ugly, but until
a) sqlite change the name
or
b) you change the namespace name

you'll be stuck with a hack!

Cordialement!

Daniel


2017-04-10 5:11 GMT-04:00 dip <[hidden email]>:

> I am mixing C and C++ code. My code is in C++, SQLite is in C.
> Just create memory.h:
>
> namespace Mem {
> // some functions
> }
>
> And create code.cpp:
>
> #include "memory.h"
> #include "sqlite3.h"
>
> void Func()
> {
> Mem::SomeFunc(); // gives the compilation error
> }
>
> Sent with [ProtonMail](https://protonmail.com) Secure Email.
>
> -------- Original Message --------
> Subject: Re: [sqlite] "struct Mem" conflicts with namespaces/classes
> having the same name
> Local Time: April 10, 2017 2:29 AM
> UTC Time: April 9, 2017 11:29 PM
> From: [hidden email]
> To: SQLite mailing list <[hidden email]>
>
> I see no problems with C++.
>
> Mem is only foward declared, you can redefined it to whatever you want. as
> long as you do not redefined it for sqlite.c you should be good.
>
> in sqlite.h it's declared:
>
> struct Mem;
>
> so in your code if you do:
>
> struct Mem { int a;int b;} then your definition will be used for your code.
>
> as sqlite is only using pointer, and has his own definition, I do not see
> the problem.
>
> it breaks the ODR, but as I previously said it's used/allocated internally
> by sqlite which should never see your definition.
>
> can you explain in more detail what is happening ?
>
> can you make a small reproduceable sample ?
>
> also are you mixing C++ & C, or is your code all in c ?
>
> Daniel
>
> 2017-04-09 15:49 GMT-04:00 dip <[hidden email]>:
>
> > sqlite3.c is C file. C does not support namespaces.
> > Even though another project files are .cpp, sqlite3.c is still compiled
> as
> > C language source.
> > Therefore, no ability to use "using namespace" in sqlite3.c.
> > Also, "using namespace" does not actually put functions in the source in
> > namespace. It just helps it find another functions without specifying
> > namespace name.
> >
> > Sent with [ProtonMail](https://protonmail.com) Secure Email.
> >
> > -------- Original Message --------
> > Subject: Re: [sqlite] "struct Mem" conflicts with namespaces/classes
> > having the same name
> > Local Time: April 9, 2017 10:23 PM
> > UTC Time: April 9, 2017 7:23 PM
> > From: [hidden email]
> > To: SQLite mailing list <[hidden email]>
> >
> > On Sun, Apr 9, 2017 at 12:20 PM, Richard Damon <[hidden email]
> >
> > wrote:
> >
> > > On 4/9/17 1:49 PM, Olivier Mascia wrote:
> > >
> > >> Le 9 avr. 2017 à 18:49, dip <[hidden email]> a écrit :
> > >>>
> > >>> I downloaded latest SQLite Amalgamation (v 3.18.0) to embed it in my
> > >>> project.
> > >>> After that I got a lot of errors while compiling (compiler is
> Microsoft
> > >>> Visual Studio 2017).
> > >>> Errors were caused by the following line in sqlite3.h:
> > >>>
> > >>> typedef struct Mem sqlite3_value;
> > >>>
> > >>> The reason is that I have the namespace with the same name.
> > >>> So I have a suggestion to rename "struct Mem" to something else (add
> > >>> prefix to it) because "Mem" is a very common name like "input" or
> > "data" or
> > >>> "buffer" and there may be classes or namespaces having the same name.
> > >>>
> > >> The way to overcome this completely in large programmings using many
> > >> libraries is to include sqlite3.h within a namespace. Not something
> that
> > >> SQLite code must do itself: that's best handled at the user project
> > level.
> > >>
> > >> The problem with this is that if the header file is put in a namespace
> > in
> > > the user code, then the source file that defines these functions needs
> to
> > > also be changed to put the files in that same namespace, or the things
> > > being defined won't be found.
> > >
> > > think that's what 'use namespace' is for
> >
> > > --
> > > Richard Damon
> > >
> > >
> > > _______________________________________________
> > > sqlite-users mailing list
> > > [hidden email]
> > > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> > >
> > _______________________________________________
> > sqlite-users mailing list
> > [hidden email]
> > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> > _______________________________________________
> > sqlite-users mailing list
> > [hidden email]
> > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> >
>
> --
> Daniel
> *L'action accède à la perfection quand, bien que vivant, vous êtes déjà
> mort*
> *Bunan*
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>



--
Daniel
*L'action accède à la perfection quand, bien que vivant, vous êtes déjà
mort*
*Bunan*
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Olivier Mascia
In reply to this post by dip
> Le 10 avr. 2017 à 11:11, dip <[hidden email]> a écrit :
>
> I am mixing C and C++ code. My code is in C++, SQLite is in C.
> Just create memory.h:
>
> namespace Mem {
> // some functions
> }
>
> And create code.cpp:
>
> #include "memory.h"
> #include "sqlite3.h"
>
> void Func()
> {
> Mem::SomeFunc(); // gives the compilation error
> }

This is where I do:

#include "memory.h"
namespace sqlite
{
#include "sqlite3.h"
}

And the conflict with your Mem goes away for the price of qualifying your references to SQLite symbols with 'sqlite::'. It fits me easily because we have our own slim C++ wrapper around SQLite C API, so these prefixed references are only slightly annoying (length of text) in the wrapper code. It might of course not fit you and having sqlite3.h not exposing that Mem in the public namespace is certainly the long term better solution for everyone.

--
Best Regards, Meilleures salutations, Met vriendelijke groeten,
Olivier Mascia, http://integral.software



_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Bob Friesenhahn
On Mon, 10 Apr 2017, Olivier Mascia wrote:

>
> This is where I do:
>
> #include "memory.h"
> namespace sqlite
> {
> #include "sqlite3.h"
> }
>
> And the conflict with your Mem goes away for the price of qualifying
> your references to SQLite symbols with 'sqlite::'. It fits me easily
> because we have our own slim C++ wrapper around SQLite C API, so
> these prefixed references are only slightly annoying (length of
> text) in the wrapper code. It might of course not fit you and having
> sqlite3.h not exposing that Mem in the public namespace is certainly
> the long term better solution for everyone.

A way to get rid of the annoying 'sqlite::' prefix for plain C
functions is to import the functions actually planned to be used into
global scope or into the namespace of the using code:

namespace MyNamespace
{
   using sqlite:sqlite3_exec;
}

Bob
--
Bob Friesenhahn
[hidden email], http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Daniel Anderson
as Sqlite is already within extern "C"

I'm wondering how your namespace trick can work ?



2017-04-10 9:41 GMT-04:00 Bob Friesenhahn <[hidden email]>:

> On Mon, 10 Apr 2017, Olivier Mascia wrote:
>
>>
>> This is where I do:
>>
>> #include "memory.h"
>> namespace sqlite
>> {
>> #include "sqlite3.h"
>> }
>>
>> And the conflict with your Mem goes away for the price of qualifying your
>> references to SQLite symbols with 'sqlite::'. It fits me easily because we
>> have our own slim C++ wrapper around SQLite C API, so these prefixed
>> references are only slightly annoying (length of text) in the wrapper code.
>> It might of course not fit you and having sqlite3.h not exposing that Mem
>> in the public namespace is certainly the long term better solution for
>> everyone.
>>
>
> A way to get rid of the annoying 'sqlite::' prefix for plain C functions
> is to import the functions actually planned to be used into global scope or
> into the namespace of the using code:
>
> namespace MyNamespace
> {
>   using sqlite:sqlite3_exec;
> }
>
> Bob
> --
> Bob Friesenhahn
> [hidden email], http://www.simplesystems.org/users/bfriesen/
> GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>



--
Daniel
*L'action accède à la perfection quand, bien que vivant, vous êtes déjà
mort*
*Bunan*
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Olivier Mascia
> Le 10 avr. 2017 à 16:21, Daniel Anderson <[hidden email]> a écrit :
>
> as Sqlite is already within extern "C"
>
> I'm wondering how your namespace trick can work ?


Both are simply unrelated.
extern "C" is a linkage specification.
Not a namespace declaration.

--
Best Regards, Meilleures salutations, Met vriendelijke groeten,
Olivier Mascia, http://integral.software


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "struct Mem" conflicts with namespaces/classes having the same name

Daniel Anderson
ok, but then
namespace ns1
{
extern "C" int ert(void) { return 9; }
};

namespace ns2
{
extern "C" int ert(void);
};

are both the same function !

it would be simpler in the sqlite case to define Mem to something else
before include, and then undef it

instead of playing with namespace


2017-04-10 10:43 GMT-04:00 Olivier Mascia <[hidden email]>:

> > Le 10 avr. 2017 à 16:21, Daniel Anderson <[hidden email]> a écrit :
> >
> > as Sqlite is already within extern "C"
> >
> > I'm wondering how your namespace trick can work ?
>
>
> Both are simply unrelated.
> extern "C" is a linkage specification.
> Not a namespace declaration.
>
> --
> Best Regards, Meilleures salutations, Met vriendelijke groeten,
> Olivier Mascia, http://integral.software
>
>
> _______________________________________________
> sqlite-users mailing list
> [hidden email]
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>



--
Daniel
*L'action accède à la perfection quand, bien que vivant, vous êtes déjà
mort*
*Bunan*
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...