March 22, a few Bothers ME small problems

xiaoxiao2021-03-06  20

Too bad, just hit it, I was closed,

The first is Typedef, always see, but you really haven't used it.

If you don't have to use Typedef

#include struct _shit {Int a, b;} shi, * pshi; void main (void) {

Struct _shit p; struct _shit * p2; p2 = & p; p2-> a = 5; Printf ("% d / n", p2-> a); shi.a = 1; pshi = & shi; pshi-> b = 2; Printf ("SHI's A:% D B:% D / N", pshi-> a, shi.b);}

SHI and PSHI are just a normal struct _shit variable and pointer, and the P and P2 in main () does not differ, define struct _shit variables and pointers must also use struct _shit p; sturct _shit * p2;

If you use Typedef

#include typedef struct _shit {Int a, b;} shi, * pshi; void main (void) {shi p; pshi p2; p2 = & p; p2-> a = 5; Printf ("% D / N ", p2-> a);} SHI and PSHI become the type of struct _shit and its pointer type, so Shi P can be used when defining struct _shit variables and pointers; and PSHI P2;

In addition, as long as it is a pointer, no matter what point, it is 4 bytes;

/ / -------------------------------------------------------------------------------------------- --------------------------------------------

In addition, it is C & it's, saying is address reference, in fact, ink to C, and I don't like it when I used C .

#include

Class Shit {public: Int a, b; public: int shi (void);}; int func (shit * s); int main (void) {shit shi, * dabian; dabian = & shi; func (dabian); shi . SHI (); Printf ("% D% D / N", shi.a, shi.b); Printf ("SIZE% D / N", SIZEOF (Dabian); Return 0;} // --- -------------------------------------------------- --------------- Int func (shit * s) {s-> a = 5; return 0;} // -------------- -------------------------------------------------- ---- INT Shit :: shi (void) {this-> b = 3; return 0;} // ------------------------ --------------------------------------------

In this small program very explanation

If it is int func (shit * s), it is clearly to pass the type of pointer, or reference the variable address FUNC (& Shi),

If it is int func (shit * & s), there is also no problem with the pointer type, just when & do not exist, their compilation is exactly the same. But because these two forms define the virtual function S It became a pointer, so in the FUNC function, use the S as a pointer, use both ->, if it is int func (shit & s), then pass the variable or object func (shi), in the function func Conversion Sb is used as a variable, and SB is like a pointer, but it is also like this.

It is difficult to remember that the type of C is very difficult. It is what it is. It is okay to it, but in the assembler, whether it is a ginseng is called a pointer shit * s or shit * & S is also Shit & S, all of them, the sump address in the stack

13: Shit shi, * dabian; 14: dabian = & shi; 00401169 8D 45 F8 LEA EAX, [EBP-8] 0040116C 89 45 F4 MOV DWORD PTR [EBP-0CH], EAX15: FUNC (shi); 0040116F 8D 4D F8 Lea ECX, [EBP-8] 00401172 51 Push ECX00401173 E8 8D FE FF FF CALL @ ilt 0 (Func) (00401005) 00401178 83 C4 04 Add ESP, 4

转载请注明原文地址:https://www.9cbs.com/read-44266.html

New Post(0)