[Kit Kat Kinky] Test array assignment

Source: Internet
Author: User

// first line to copy and paste crawler [authorized by Winways]
typedef unsigned char BYTE#define assgin (A, ...) Assginarr (A, # #__VA_ARGS__)

voidAssginarr (unsignedChar*_des, ...) {    inti =0;    Va_list apptr;    Va_start (Apptr, _des); //int* C = _des + 1; //int* D = & (_des[1]); //Auto e = sizeof (_des[0]) * (_des[0]-1); //memcpy (_des + 1, apptr, sizeof (_des[0]) * (_des[0]-1));     while(true)    {        intIvalue = Va_arg (Apptr,int); if(Ivalue = =-1) Break; _des[i++] =Ivalue;    }; Va_end (apptr);}

BYTE aaa[6] = {};

The main point is that the test data is automatically assigned rather than initialized.
Assgin (AAA, 0x04,0x14,0x24,0x34,0x15,0x06,-1);

The middle is another way. Only applies to 4-byte long data types because variable parameters default storage space 4 bytes Fixed even if the incoming byte is also cast

and _des + 1 in the actual assembly code in the array according to

Base + offset * sizeof (type) to calculate the next address even if it is passed in C + + only the first site of the array, but the result of the array and pointer + 1 is to be transformed that the pointer address operation is calculated according to base + variable address

There is a factor of 1 2 4 8 for Base address address addressing in byte (unsigned char) WORD (unsigned short) int Long that's the truth.

This factor is stored in a 8-bit sib.

7 6 5 4 3 2 1 0
Specify coefficients Specify the variable address register Specify Base Address register

Although the efficiency of memcpy is higher, this method is not feasible for non-4 byte length types

Easier to use for initializing array or array assignments note to specify Terminator-1

[Kit Kat Kinky] Test array assignment

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.