hello guys,
can we use same name for both structure name and it's variable.
thak u
bye
srinu
hello guys,
can we use same name for both structure name and it's variable.
thak u
bye
srinu
srinu
Yes, you can.
Code:struct data { int data; }data; struct { int data; }data;
Last edited by shaik786; 06-24-2002 at 05:23 AM.
struct Data_t Data;Code:struct Data_t { int var; };
...
That's how I would do it, rather than make the code confusing. Apparently the worst thing that you have to watch out for is defining a local variable within a function with the same name as a global variable (that might be in a #include file). That will get you into trouble. The use of '_t' stands for 'type'.
I think this is better, it's been many years since I programmed.Code:struct meaninglesslabel { int var; }Data_t;
>can we use same name for both structure name and it's variable.
Sure, they're in different namespaces so you can do something like this:
From there you can only access the member foo by using the . or -> operators. Because of the typedef, you can also omit the required struct keyword when you create an instance of foo:Code:typedef struct foo { int foo; } foo;
struct foo var;
or
foo var;
Will both create an instance of foo. This is because struct foo is the tag for a struct and thanks to typedef, foo is a new type, shorthand for struct foo { int foo; }. If you find that confusing, imagine this feature being used in real code. :P
-Prelude
My best code is written with the delete key.