|
I have some code:
sid->identifier_authority
where sid is declared as:
const SID* sid
and the project say that sid is targeting to windows (WinNT.h):
typedef struct _SID {
...
} SID, *PISID;
but I also have (in some header file) inside my project another SID struct declared:
#ifdef SID
typedef struct {
u8 sub_authority_count;
SID_IDENTIFIER_AUTHORITY identifier_authority;
}SID;
#endif
how can I do to sid be as my SID struct, not as _SID windows struct ?
|
|
|
|
|
You need to use a namespace here to remove the ambiguity between types.
Check this thread to see how this can be solved, Why doesn't ANSI C have namespaces? - Stack Overflow.
Quote: how can I do to sid be as my SID struct, not as _SID windows struct ? Are you including both the header files? If they are in separate header files, you can try avoiding including a header file and SID will automatically be of your choice.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Is included only myfile.h, not WinNT.h ... still, the code take _SID because my SID structure is hidden after an #ifdef SID ... the fact is that if I define a SID I got another errors. And for that error see this post: Re: Redirect to my struct - C / C++ / MFC Discussion Boards[^]
modified 8-Jan-20 5:26am.
|
|
|
|
|
Inside myheader.h there is a lot for other structs and defines that is in conflict with those from Windows. SID_IDENTIFIER_AUTHORITY for example ... So, removing or renaming is not an option (I guess). But I am not figure out how to solve this conflict with namespacing ...
|
|
|
|
|
This is just going to lead to more and more problems for you. You need to isolate your definitions from the ones in Windows. You can do it with the use of namespaces, or changing the names in your local definitions. But either way, until you fix this issue you are wasting your time trying to build any of the code.
|
|
|
|
|
Thank you Richard.
"You can do it with the use of namespaces"
Can you give me a little pseudocode that show me how to do it ?
|
|
|
|
|
Namespaces are a C++ feature, and not available if you are using C only. Basically a namespace wraps a set of definitions so that they can be uniquely identified within a source listing. eg:
namespace MyLib {
class A {
int x;
...
};
}
namespace MyProj {
class A {
int y;
...
};
}
...
int main() {
MyProj::A a1; MyLib::A a2;
a1.y = a2.y; }
update:The last line of the sample code, above should be a1.y = a2.x , apologies for any confusion
If, however, you are using C, you've got two choices.
1) refactor you project so that your SID and the system SID never appear in the same source code file (otherwise known as a translation unit). That's not always possible, and even when it is, it's usually requires a lot of thought, care, and effort.
2) refactor you project and rename your SID to something else, eg MyProg_SID. That's still a lot of work, but its' probably a lot less work than option 1, above. Additionally, your IDE might provide a renaming tool that will do the grunt work for you. If not, you might be able to use the find and replace feature of your favorite text editor.
modified 8-Jan-20 10:07am.
|
|
|
|
|
That C code I modified as C++ code, so I could use namespaces 
|
|
|
|
|
It is not that straightforward unfortunately. A namespace is a qualifier that allows you to have objects with the same name in a single compilation unit. As a simple example:
namespace foo
{
typedef struct
{
int bar;
} FOOBAR;
};
namespace gaa
{
typedef struct
{
char bar;
} FOOBAR;
};
int main
{
foo::FOOBAR foobar; foobar.bar = 10;
gaa::FOOBAR gaabar; gaabar.bar = 'X';
}
|
|
|
|
|
The field names are not an issue you just need the struct, typedef and pointer to have different names
As Richard said it's going to bite you find a different name.
If you want to try a different name with minimal typing go to your file myheader.h and at the top after the guard put these
#define _SID _mySID
#define SID mySID
#define PISID myPISID
now go to the very bottom and put these
#undef _SID
#undef SID
#undef PISID
Now your SID is called mySID to all other units because it just does a text substitute
If you are happy it is all well the make the change permanently using Edit->find & replace on the file using Visual Studio.
In vino veritas
|
|
|
|
|
Interesting idea, and it works for this case, but inside that myheader.h, I have several structs with names as windows have ... so, I guess is not productive renaming structs ... that is why I am thinking seriously at namespaces ... but I don't know how to use it yet.
modified 9-Jan-20 1:33am.
|
|
|
|
|
Why are you including two definitions for the same structure? Either remove the duplicate or rename one of them to keep them unique.
|
|
|
|
|
Maybe it's a typo?
You could try to change #ifdef to #ifndef ; which would make much more sense anyway since there is not point in defining something which has already been defined elsewhere.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
Of course I tried with #ifndef , but I got error: error C2371: 'SID' : redefinition; different basic types
|
|
|
|
|
This doesn't do what you think it does:
typedef struct_SID {
...
} SID, *PISID
#ifdef SID
typedef struct {
...
}SID;
#endif
#ifdef,#undef etc only refers to preprocessor tokens. In C/C++, you can not undefine (or redefine) a previously defined item. e.g. the following is not valid
int x;
#ifdef x // only if preprocessor token 'x' exists
#undef x // doesn't undefine int x
struct { int i;
double d;
} x;
#endif
...
x myX;
|
|
|
|
|
I guess I know that. In WinNT.h I got:
typedef struct _SID {
....
} SID, *PISID;
and in myheader.h I got:
#ifdef SID
typedef struct {
...
}SID;
#endif
and my project take SID from WinNT.h, and I want to take it from myheader.h. Even if I get out #ifdef SID and #endif from myheader.h, the situation is the same. And moreover, inside myheader.h I have several struct with the same naming as windows has.
|
|
|
|
|
_Flaviu wrote:
#ifdef SID
typedef ... SID;
Sorry to be rude, but that's bullsh1t! If there really is a #define for the symbol SID anywhere in your code or your precompiler options, then your ccode will most likely never compile, because any attempt to use, declare or otherwise reference a struct SID will be turned into garbage by the precompiler which replaces the symbol with something else!
So, unless and until you make sure that nobody does such a #define , there is no point looking further! And then, of course, the #ifdef makes no sense - not that it did before.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
|
|
If I wrote:
#define major(dev) gnu_dev_major(dev)
#define minor(dev) gnu_dev_minor(dev)
then I got following error:
error C3861: 'gnu_dev_major': identifier not found
error C3861: 'gnu_dev_minor': identifier not found
I have arrived in a kind of same error ...
|
|
|
|
|
Didn't you read the link I have posted? There are some definition of the functions...
Just try something like
unsigned int gnu_dev_major (unsigned long long int __dev)
{
return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
}
|
|
|
|
|
Ahh, I didn't read whole source code. I am struggle to solve another errors. But I implemented what you said and I get rid of that error. Thank you Victor !!!
|
|
|
|
|
You are welcome!
But be sure that this function definition is correct!
|
|
|
|
|
It looks like you're trying to use a GCC/linux function under Windows. Does that even make any sense? I mean, I've seen that you got it to compile now, but that doesn't mean your program will do what you expect it to!
I'm not familiar with gcc/linux and these functions, but if what Victor posted corresponds to the original implementation, it looks like dev is some version identifier composed of a major and minor version number. The way such versions are composed in Windows may be entirely different! There's no common scheme for it between different applications, compilers, or the OS itself. So don't expect any correct results from a Linux implementation!
To properly solve this issue you should find out who uses these functions and what are they expected to return. Only then will you be able to implement a proper replacement. Or, better, find the corresponding functions provided in Windows.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
"find the corresponding functions provided in Windows" I am perfectly agree with you. This is another part of work. And I am not sure that I'll find such replacement.
modified 9-Jan-20 4:56am.
|
|
|
|