tags:

views:

96

answers:

4
+1  Q: 

Redefinition in C

hello, can somebody explain me about redefinition in C:

is it possible to do something like this

typedef struct NumberContainer* ptrNumberContainer;

and after that

  typedef struct NumberContainer* ptrCall;

may it cause some problems during linkage? thanks in advance

+5  A: 

No, that's perfectly OK - you have two synonyms for the same underlying type - this is quite common. However, the practice of hiding the fact that something is a pointer by using a typedef is generally viewed as bad practice in C.

anon
A: 

This is not redefinition. Redefinition refers to macro definitions:

#define FOOBAR 1
#undef FOOBAR
#define FOOBAR 2
Marcelo Cantos
I'm sorry, maybe I didn't explain it correctly but Neil Butterworth understood what I mean
lego69
can You also give your explanation?
lego69
@Marcelo Surely you can also have errors redefining struct, functions etc?
anon
After an initial misreading, I did understand what you were asking, and the current answer reflects this. As the other answers point out, what are you doing is legal. What I was pointing out is that you are not actually redefining anything (you cannot redefine symbols in C). I was also trying to suggest where you might have gotten the expression from.
Marcelo Cantos
Just to clarify, you cannot redefine _compiler_ symbols. You can of course redefine macro symbols, which was the point I was making.
Marcelo Cantos
I'm not sure what you are asking, Neil. You will certainly have errors, since, in general, you can't redefine such things at all. I was merely observing that what the OP was doing doesn't go by the name "redefinition".
Marcelo Cantos
+1  A: 

Of course it's possible. Defines two different type names to mean the same thing.

Pavel Radzivilovsky
A: 

In that case, ptrCall will actually refer to the same type as ptrNumberContainer. I think they will also be compatible compile time. So you can say, for example:

ptrNumberContainer p1;
ptrCall p2;

Then these will work:

p1 = p2;
*p1 = *p2;
petersohn