Thread GUIs in C für Windows (33 answers)
Opened by SirLant at 2003-08-11 01:50

esskar
 2003-08-11 22:04
#10815 #10815
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
C:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
struct test1
{
int i;
char c;
char text[512];
}

struct test1 varstruct1;

varstruct1.i = 10;
varstruct1.c = 'a';
strncpy(varstruct.text, "Das ist ein Text", sizeof(varstruct.text));

void function1(const struct test1 * ptr) //Pointer
{
printf("%i\n", ptr->i);
}

function1(&varstruct1);

typedef struct test2
{
int i;
char c;
char text[512];
} Test2, *PTest2;

Test2 varstruct2;

void function2(const PTest2 ptr) //Pointer
{
printf("%s\n", ptr->text);
}

function(&varstruct2);


C++
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
struct test3
{
int i;
char c;
char text[512];

test2() { *text = 0; i = 0; c = 0; } // konstructor
void print() { printf("%i, %s, %s\n", i, &c, text); }
}

test3 varstruct3;

varstruct.print();

varstruct.i = 10;

varstruct.print();

void function3(const test3 * ptr) // pointer
{
test3->print();
}

void funbction3(const test3 & ref) // referenz
{
ref.print();
}


im grunde ist unter c/c++ kein unterschied zwischen pointer und referenz gegeben... der compiler biegt das richtig...
aber eine referenz zeigt immer auf güligen speicher, wohin gegen ein pointer auch auf 0 oder eine undefinierte stelle im speicher zeigen kann!

View full thread GUIs in C für Windows