Redirect to my struct
-
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;
#endifhow can I do to sid be as my SID struct, not as _SID windows struct ?
Maybe it's a typo? You could try to change
#ifdef
to#if**n**def
; 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."
-
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](https://stackoverflow.com/questions/4396140/why-doesnt-ansi-c-have-namespaces).
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 shit 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[^] -
Maybe it's a typo? You could try to change
#ifdef
to#if**n**def
; 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."
-
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](https://stackoverflow.com/questions/4396140/why-doesnt-ansi-c-have-namespaces).
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 shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
-
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](https://stackoverflow.com/questions/4396140/why-doesnt-ansi-c-have-namespaces).
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 shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~
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 ...
-
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.
-
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; // defines an object of type class A from namespace MyProj
MyLib::A a2; // defines an object of type class A from namespace MyLiba1.y = a2.y; // don't need namespace resolution tags within function
}
**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. -
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 ?
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:
// NOTE: namespaces must be declared at file scope, or in a header
namespace foo
{
typedef struct
{
int bar;
} FOOBAR;
};namespace gaa
{
typedef struct
{
char bar;
} FOOBAR;
};// the struct name FOOBAR may now be qualified to avoid ambiguity
int main
{
foo::FOOBAR foobar; // as declared in namespace foo
foobar.bar = 10; // the variable is int typegaa::FOOBAR gaabar; // as declared in namespace gaa gaabar.bar = 'X'; // here is is char type
}
-
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;
#endifhow can I do to sid be as my SID struct, not as _SID windows struct ?
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 validint x;
#ifdef x // only if preprocessor token 'x' exists
#undef x // doesn't undefine int x
struct { // compiler error if branch taken, redifines type of x
int i;
double d;
} x;
#endif...
x myX; //compiler error: typeof x unknown -
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 ...
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 myPISIDnow go to the very bottom and put these
#undef _SID
#undef SID
#undef PISIDNow 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
-
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 myPISIDnow go to the very bottom and put these
#undef _SID
#undef SID
#undef PISIDNow 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.
-
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 validint x;
#ifdef x // only if preprocessor token 'x' exists
#undef x // doesn't undefine int x
struct { // compiler error if branch taken, redifines type of x
int i;
double d;
} x;
#endif...
x myX; //compiler error: typeof x unknownI 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;
#endifand 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. -
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; // defines an object of type class A from namespace MyProj
MyLib::A a2; // defines an object of type class A from namespace MyLiba1.y = a2.y; // don't need namespace resolution tags within function
}
**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. -
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;
#endifhow can I do to sid be as my SID struct, not as _SID windows struct ?
_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)