Abstract

During software development, novice developers usually receive a lot of error messages and just warnings of various kinds. And if the code simply won't run when there are errors, then the program usually starts when there are various warnings. And here it is important to understand what consequences the presence of warnings of various kinds can lead to. This work aims to study the code's undefined behavior when working with struc-tures in the C programming language when issuing a corresponding compiler warn-ing about returning the address of a local or temporary variable. In the procedural programming language C, there is an ancestor of the OOP class — the structure struct, which encapsulates only the state of the entity. And the question arises — is it possible to work with separate components-fields of such a structure analogously to OOP languages? For research, a simple structure was taken, which contains information about the person's name, surname, and phone number. To access parts of the structure, pseudogetters were used — functions that returned a pointer to the corresponding part of the structure. The research was conducted in the Visual Studio 2019 environment under the control of the Windows 10 operating system when the default C language standard - MSVC and the more modern ISO standard C17 (2018) was selected in the project settings. As a result, a truly undefined behavior of the code was obtained, when the re-sult of the work of the code fragment (function call) depends on many factors: the length of the array, the standard of the C language, the position of a certain part in the structure. An attempt to conduct similar research under the control of the Linux Mint oper-ating system using the gcc compiler version 5.4 was unsuccessful. When compiling the code, a similar warning about returning the address of a local variable was also issued, as in the case of Visual Studio. But when the program was launched, it sim-ply crashed with a message about a segmentation error. Thus, both the Visual Studio 2019 compiler and the gcc compiler warned us about undefined code behavior. But this uncertain behavior was radically different for operating systems and compilers. If after gcc under the Linux OS, the code simply does not work at all and the program stops its work with a segmentation error mes-sage, then after Visual Studio under Windows, inexperienced developers with im-proper testing and verification of the code can miss the code that "does not always work", which can lead to unexpected results, not always pleasant, to say the least. And that's why software developers, especially beginners, should pay attention not only to compilation errors but also to warnings, even if the code works.

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.