Get out of your own Windows development and incorporate the development of the program ape

Source: Internet
Author: User

Since 2014.7.9 to join the * * Soft research, has been doing the development of Windows UI, the main language is C + +; Time passed quickly, and there was no time. Perhaps there is no energy to write some records, but the more you feel the need to write documents, then the decisive application of the blog, recorded the previous, The next step in the process of life, one is to encourage their own continuous precipitation technology, professional culture and so on; In addition, there is also a study that can belong to their own can be browsed, memories. The time is very late, the eyes are somewhat hazy;

Just looked at the "System Program Ape's growth plan", which preached a simple mechanism of variable parameters analysis; is roughly a compression stack matching;

printf Presumably everyone will be familiar with the use of, she is a typical variable parameter list ....

int __cdecl printf (const char *format, ...) ;

Variable parameters, about so templated,

1) He must be at least a given parameter to appear after, that is, can not reach such a fork of the printf (...);

2) The first parameter, comma separated, continued "..." three points, to achieve the C language syntax requirements

Such a function, can be called variable parameter function;

void Fun ()
{
int i = +, J = N, k = +, L = 400;
printf ("%d,%d,%d", I, J, K, L);
}

The system will be in the stack area in order L, K, J, I open Space, the declaration of variables is right-to-left to expand;

In my Win8 the 64-bit system opens up memory, in turn

+ &i 0x0018fe4c int *
+&j 0x0018fe40 int *
+&k0x0018fe34 int *
+&l 0x0018fe28 int *

They are a stack of process, the address of the stack is to the low address extension, but do not understand that the interval is 12?!! Also ask a friend to gossip about;

L,k,j,i the stack in turn; I think three%d, maybe also press stack another stack;

Stack A Stack b

+ &i 0x0018fe4c int *%d
+&j 0x0018fe40 int *%d
+&k0x0018fe34 int *%d
+&l 0x0018fe28 int *

Two stacks, go to the first%d, go to &i;---"Go to 2nd%d, go &j;---" Go to 3rd%d, go &k;---".... That's why K can't print.

The result is really:

100, 200, 300

Of course, printf may be such a stack comparison of stacks; When you write a variable parameter function, you can use the number of parameters, that is, the first parameter to the variable number of parameters to wear, which will be followed by a pointer to find;

It's really simple, like add (int num, ...)

Add (1, 100);

Add (2, 20, 30);

Add (4, 1, 2, 3, 5);

The pointer navigates directly to the first parameter, i.e. the address of the parameter 1, the addition operation; The pointer offsets the next parameter's byte, then adds .... Until the last parameter is added.

This proves that, a lot of things are very interesting, we really can not old four complaining about nothing, do not understand, no matter, a day to record a little, a day mood will change a bit. Come on, little weight! Go to bed!!! That address offset 12, you can gossip about it!

Get out of your own Windows development and incorporate the development of the program ape

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.