Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between AIX and Linux using the C++ compiler

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the difference between AIX and Linux using the C++ compiler". In daily operation, I believe many people have doubts about the difference between AIX and Linux using the C++ compiler. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "what is the difference between AIX and Linux using the C++ compiler?" Next, please follow the editor to study!

The xlc++ compiler is used on AIX, and the glossy + compiler is used on Linux. For behaviors that are not strictly defined in the C standard, the two compilers may not handle the same way, resulting in some bug. The problems focus on the following areas

Example of BUG type

Xlc++ compiler

Glossy + compiler

Treatment method

S = "12"

Sprintf (r, "s", s)

S less than four places on the left to fill'0'

R = "0012"

S less than four left filling''

R = "12"

Add check code

Char* p = r

For (; * p = ='; + + p)

* paired pictures 0'

File descriptor

When file=NULL, write content

Fprintf (file, "…")

Unable to write, the program continues to execute downward.

Collapse

Increase judgment

If (file! = NULL)

Memcpy out of bounds to copy array data

The address between variables is scattered, and the array itself is out of bounds, which has no effect on other variables, and can generally produce normal results.

The addresses between variables are closely adjacent, the array itself is out of bounds, and the values of adjacent variables are overwritten, resulting in an exception.

Check the corresponding location to copy the memory length to avoid crossing the boundary.

The ret structure contains the amt variable, which is not initialized before use.

Amt default value 0.0

The default value of amt is a very large positive number, causing the program to crash

Add initialization processing memset (& ret,'\ 0operations, sizeof (ret))

If AIX is a 32-bit version and Linux is a 64-bit version, the length of some variables will change. The following table should be noted:

Variable type

32 bit

64 bit

BUG types and treatment

Long

4 byt

8 byte

The third parameter of some memcpy and strncpy in the code is sizeof (pointer), which causes the copy memory length to change (4 to 8) after migration. It needs to be modified according to the situation to avoid using sizeof to manipulate variables such as pointers that vary in length with the platform. When the array name is used as a parameter, it is also equivalent to a pointer, and the sizeof operation should not be performed.

Pointer

4 byt

8 byte

At this point, the study on "what is the difference between AIX and Linux using C++ compiler" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report