Variable parameter record in C

Source: Internet
Author: User

"Sometimes, I am confused when I choose to repost and create an original project, and I am so confused about how much I know"

--------------------------------------

Preface:

Although variable parameters can be executed poorly, they may be affected by the platform, such as the CPU arch, the size end, And the stack growth. However, if you do not consider these parameters, you can use them to complete some tips.

Note: # pragma print ???

1. va_arg

 
Va_arg (ARGs, bool) va_arg (ARGs, char)

These two statements run normally, but note prompts in Linux compilation that there will be a command error and the runtime will crash.

Let's first look at the macro definition of vadefs. h In Windows:

 
# Elif defined (_ m_ix86) # DEFINE _ intsizeof (N) (sizeof (n) + sizeof (INT)-1 )&~ (Sizeof (INT)-1) # DEFINE _ crt_va_start (AP, V) (AP = (va_list) _ addressof (v) + _ intsizeof (v )) # DEFINE _ crt_va_arg (AP, t) (* (T *) (AP + = _ intsizeof (t)-_ intsizeof (t ))) # DEFINE _ crt_va_end (AP) (AP = (va_list) 0)

Linux.

Why is there a problem with the above two statements in Linux? Haha, the compilation still looks good at the prompts and warning information

"'Short unsigned int' is promoted to 'int' when passed through '...'"

"'Char 'is promoted to 'int' when passed through'... '" // when passing the char type, it will be upgraded to the int type.

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.