Is struct in C and C++ the same?
Struct in C and C++
Started by dirkfirst, Jun 12 2006 08:02 AM
9 replies to this topic
#1
Posted 12 June 2006 - 08:02 AM
|
|
|
#2
Posted 12 June 2006 - 01:51 PM
dirkfirst said:
Is struct in C and C++ the same?
No they are not
#3
Posted 14 June 2006 - 01:14 PM
Errm, you use them exactly the same way:
C:
typedef struct blabla
{
int x;
char z;
}
c++:
typedef struct blabla
{
int x;
char z;
}
C:
typedef struct blabla
{
int x;
char z;
}
c++:
typedef struct blabla
{
int x;
char z;
}
#4
Posted 21 June 2006 - 12:53 PM
Well, accually let me correct myself.
In some compilers ( Turbo C for example ), all C struct operations and declares must begin with `struct`:
But other than that you use them the exact same way.
In some compilers ( Turbo C for example ), all C struct operations and declares must begin with `struct`:
typedef struct MNT_DEV{
byte oport;
byte iport;
};
void main(void)
{
struct MNT_DEV mnt_pt;
struct mnt_pt.iport = 0x02; /* Normally mnt_pt.iport = 0x02; would be all you need */
}
But other than that you use them the exact same way.
#5
Posted 22 June 2006 - 11:58 AM
So they are the same or they are not? lol
#6
Posted 22 June 2006 - 12:01 PM
yes, the only differnce is that sometimes c compilers will require you put the keyword "struct" infront of all structure operations, ie:
struct header.i = 0; //Works header.i = 0; //Nope, no worky
#7
Guest_Kaabi_*
Posted 03 July 2006 - 03:47 PM
Guest_Kaabi_*
I'd always thought the structure was the same, and it appears I was right, although I didn't know about that "struct" thing.
#8
Posted 04 March 2008 - 08:47 PM
hi according to what i undrestand from the link jonh gave us there should a difference btw structs in C and c++
structs don't copy in C. That is, if a and b are structs then the line a = b; doesn't work. Nor will structs be fed into functions as arguments. The only way to deal with them sensibly is to use pointers to them, or to write functions to copy their elements explicitly
from :Differences between C and C++
structs don't copy in C. That is, if a and b are structs then the line a = b; doesn't work. Nor will structs be fed into functions as arguments. The only way to deal with them sensibly is to use pointers to them, or to write functions to copy their elements explicitly
from :Differences between C and C++
#9
Posted 04 March 2008 - 09:50 PM
Please don't bump years-old threads, kia!
#10
Posted 05 March 2008 - 03:28 AM
ok but tel me make things clear first i didnt do this by porpose if i choosed these topic it is because i m actualy taking some course in struct i mean we reach the chapter about struct so this why anyway sorry and i didnt know that i may get warnig for this so sory then for this mistake :( :(
hope my sory ll be accepted
hope my sory ll be accepted


Sign In
Create Account


Back to top









