Question: How many programming languages are there as of April 2019?

C (programming language)

Even char and long can be the same size if one byte is 32 bits or more, but such platforms will be very rare or will not exist.


Question: How many programming languages are there as of April 2019?

C (programming language)

The standard ensures that the char type is always 1 byte.


Question: How many programming languages are there as of April 2019?

C (programming language)

The byte size in bits is determined by the CHAR_BIT constant from the limits.h header file; for POSIX-compatible systems it is 8 bits [13].


Question: How many programming languages are there as of April 2019?

C (programming language)

The minimum range of values of integer types according to the standard is determined from - (2N-1-1) to 2N-1-1 for signed types and from 0 to 2N for unsigned types, where N is the bit depth of the type.


Question: How many programming languages are there as of April 2019?

C (programming language)

Compiler implementations can extend this range as they see fit.


Question: How many programming languages are there as of April 2019?

C (programming language)

In practice, the range from -2N-1 to 2N-1-1 is more often used for signed types.


Question: How many programming languages are there as of April 2019?

C (programming language)

The minimum and maximum values of each type are specified in the limits.h file as macro definitions.


Question: How many programming languages are there as of April 2019?

C (programming language)

Special attention should be paid to the char type.


Question: How many programming languages are there as of April 2019?

C (programming language)

Formally, this is a separate type, but in fact char is equivalent to either signed char or unsigned char, depending on the compiler.


Question: How many programming languages are there as of April 2019?

C (programming language)

To avoid confusion between type sizes, C99 introduced new data types described in the stdint.h file.


Question: How many programming languages are there as of April 2019?

C (programming language)

Among them are such types as: Intn_T, Int_Leastn_t, Int_Fastn_t, where N = 8, 16, 32 or 64.


Question: How many programming languages are there as of April 2019?

C (programming language)

The prefix least- denotes the minimum type that can hold N bits, the fast- prefix denotes the type with a size of at least 16 bits, which is the fastest to work with on this platform.


Question: How many programming languages are there as of April 2019?

C (programming language)

Types without prefixes refer to types with a fixed size of N bits.


Question: How many programming languages are there as of April 2019?

C (programming language)

Types with least- and fast- prefixes can be considered a replacement for int, short, long types, with the only difference being that the former allow the programmer to choose between speed and size.


Question: How many programming languages are there as of April 2019?

C (programming language)

Also, from the C99 standard, the intmax_t and uintmax_t types have been added, corresponding to the largest signed and unfamiliar types, respectively.


Question: How many programming languages are there as of April 2019?

C (programming language)

These types are useful when used in macros to store intermediate or temporal values when operating on integer arguments, as they allow you to fit values of any type.


Question: How many programming languages are there as of April 2019?

C (programming language)

For example, these types are used in the Check C unit testing library integer comparison macros.


Question: How many programming languages are there as of April 2019?

C (programming language)

C has several additional integer types for safe handling of the pointer data type: intptr_t, uintptr_t, and diffptr_t.


Question: How many programming languages are there as of April 2019?

C (programming language)

The intptr_t and uintptr_t types from the C99 standard are designed to store signed and unsigned values, respectively, which can fit a pointer in size.


Question: How many programming languages are there as of April 2019?

C (programming language)

These types are often used to store an arbitrary integer in a pointer, for example, as a way to get rid of excess memory allocation when registering feedback functions [15] or when using third-party linked lists, associative arrays, and other structures in which data is stored by pointer.


Question: How many programming languages are there as of April 2019?

C (programming language)

The diffptr_t type is designed to safely store the difference between two pointers.


Question: How many programming languages are there as of April 2019?

C (programming language)

To store the size, the unsigned size_t type from the stddef.h header file is provided.


Question: How many programming languages are there as of April 2019?

C (programming language)

This type is able to hold as many bytes as possible per pointer, and is usually used to store the size in bytes.


Question: How many programming languages are there as of April 2019?

C (programming language)

A value of this particular type is returned by the sizeof operator.


Question: How many programming languages are there as of April 2019?

C (programming language)

Real numbers


Question: How many programming languages are there as of April 2019?

C (programming language)

C floating-point numbers are represented by three main types: float, double, and long double.


Question: How many programming languages are there as of April 2019?

C (programming language)

There are also two additional float_t and double_t types in the math.h header file, which correspond to at least float and double types, respectively, but may be different from them.


Question: How many programming languages are there as of April 2019?

C (programming language)

The float_t and double_t types are added to the C99 standard, and their correspondence to the main types is determined by the value of the FLT_EVAL_METHOD macro.


Question: How many programming languages are there as of April 2019?

C (programming language)

Strings


Question: How many programming languages are there as of April 2019?

C (programming language)

Zero-terminated strings


Question: How many programming languages are there as of April 2019?

C (programming language)

Despite the fact that there is no special type for strings in C as such, the language actively uses null-terminated strings.


Question: How many programming languages are there as of April 2019?

C (programming language)

ASCII strings are declared as an array of type char, the last element of which must be a character with code 0 ('\ 0').


Question: How many programming languages are there as of April 2019?

C (programming language)

It is customary to store UTF-8 strings in the same format.


Question: How many programming languages are there as of April 2019?

C (programming language)

However, all functions that work with ASCII strings treat each character as a byte, which limits the use of standard functions when using this encoding.


Question: How many programming languages are there as of April 2019?

C (programming language)

Despite the widespread use of the idea of null-terminated strings and the convenience of using them in some algorithms, they have several serious drawbacks.


Question: How many programming languages are there as of April 2019?

C (programming language)

The need to add a terminal symbol to the end of a string does not make it possible to get a substring without having to copy it, and there are no functions for working with a pointer to a substring and its length in the language is provided.


Question: How many programming languages are there as of April 2019?

C (programming language)

If you need to pre-allocate memory for the algorithm result based on the input data, you need to go through the entire string each time to calculate its length.


Question: How many programming languages are there as of April 2019?

C (programming language)

When dealing with large amounts of text, length counting can be a bottleneck.


Question: How many programming languages are there as of April 2019?

C (programming language)

Working with a string that is not terminated with zero by mistake can lead to undefined program behavior, including segmentation errors, buffer overflow errors, and vulnerabilities.


Question: How many programming languages are there as of April 2019?

C (programming language)

In modern conditions, when code performance takes precedence over memory consumption, it may be more efficient and easier to use structures that contain both the string itself and its size, for example:


Question: How many programming languages are there as of April 2019?

C (programming language)

struct string_t {


Question: How many programming languages are there as of April 2019?

C (programming language)

char *str;//pointer to a string


Question: How many programming languages are there as of April 2019?

C (programming language)

size_t str_size;//row size


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

typedef struct string_t string_t;//alternative name for simplifying code


Question: How many programming languages are there as of April 2019?

C (programming language)

An alternative approach to storing the size of a row with low memory consumption may be to add its format size to the beginning of a string.


Question: How many programming languages are there as of April 2019?

C (programming language)

This approach is used in protocol buffers, but only at the stage of data transfer, but not at the stage of data storage.


Question: How many programming languages are there as of April 2019?

C (programming language)

String literals


Question: How many programming languages are there as of April 2019?

C (programming language)

String literals in C are inherently constants.


Question: How many programming languages are there as of April 2019?

C (programming language)

When declaring, they are enclosed in double quotes, and the terminating 0 is automatically added by the compiler.


Question: How many programming languages are there as of April 2019?

C (programming language)

There are two ways to assign a string literal: by pointer and by value.


Question: How many programming languages are there as of April 2019?

C (programming language)

When assigning by a pointer, a pointer to an immutable string is entered into a variable of the char * type, i.e.


Question: How many programming languages are there as of April 2019?

C (programming language)

a constant string is formed.


Question: How many programming languages are there as of April 2019?

C (programming language)

If you enter a string literal into an array, the string is copied to the stack area.


Question: How many programming languages are there as of April 2019?

C (programming language)

1 #include <stdio.h>


Question: How many programming languages are there as of April 2019?

C (programming language)

2 #include <string.h>


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

4 int main (void)


Question: How many programming languages are there as of April 2019?

C (programming language)

5 {


Question: How many programming languages are there as of April 2019?

C (programming language)

6 const char *s1 = “Const String”;


Question: How many programming languages are there as of April 2019?

C (programming language)

7 char s2 [] = “String that can be changed”;


Question: How many programming languages are there as of April 2019?

C (programming language)

8 memcpy (s2, “c”, strlen (“c”));//replace the first letter with a small one


Question: How many programming languages are there as of April 2019?

C (programming language)

9 puts (s2);//the text of the string will be displayed


Question: How many programming languages are there as of April 2019?

C (programming language)

10 memcpy ((char *) s1, “k”, strlen (“k”));//segmentation error


Question: How many programming languages are there as of April 2019?

C (programming language)

11 puts (s1);//the line will not be executed


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

Since strings are regular character arrays, initializers can be used instead of literals if each character fits in 1 byte:char s [] = {'I', 'n', 'i', 't', 'i', 'i', 'a', 'l', 'i', 'z', 'e' , 'r', '\ 0'};


Question: How many programming languages are there as of April 2019?

C (programming language)

However, in practice, this approach makes sense only in extremely rare cases when you do not need to add a terminating zero to an ASCII string.


Question: How many programming languages are there as of April 2019?

C (programming language)

Wide rows


Question: How many programming languages are there as of April 2019?

C (programming language)

An alternative to regular strings is wide strings, where each character is stored in a special wchar_t type.


Question: How many programming languages are there as of April 2019?

C (programming language)

According to the standard, this type should be able to accommodate all the symbols of the largest existing locale.


Question: How many programming languages are there as of April 2019?

C (programming language)

Functions for working with wide strings are described in the wchar.h header file, and functions for working with wide characters are described in the wctype.h header file.


Question: How many programming languages are there as of April 2019?

C (programming language)

When declaring string literals for wide strings, the L modifier is used:


Question: How many programming languages are there as of April 2019?

C (programming language)

const wchar_t *wide_str = L"Wide Line”;


Question: How many programming languages are there as of April 2019?

C (programming language)

The wchar_t type was conceived to fit any character and wide strings to store strings of any locale, but as a result, the API was inconvenient and the implementations were platform-dependent [ 16].


Question: How many programming languages are there as of April 2019?

C (programming language)

Multibyte strings


Question: How many programming languages are there as of April 2019?

C (programming language)

There are many different encodings in which a single character can be programmed with different numbers of bytes.


Question: How many programming languages are there as of April 2019?

C (programming language)

These encodings are called multibyte encodings.


Question: How many programming languages are there as of April 2019?

C (programming language)

UTF-8 also applies to them.


Question: How many programming languages are there as of April 2019?

C (programming language)

C has a set of functions for converting strings from multibyte strings within the current locale to wide and vice versa.


Question: How many programming languages are there as of April 2019?

C (programming language)

The functions for working with multibyte characters have the mb prefix or suffix and are described in the stdlib.h header file.


Question: How many programming languages are there as of April 2019?

C (programming language)

To support multibyte strings in C programs, these strings must be maintained at the current locale level.


Question: How many programming languages are there as of April 2019?

C (programming language)

Starting with the C11 standard, the language also supports 16-bit and 32-bit wide multibyte strings with the corresponding char16_t and char32_t character types from the uchar.h header file, as well as declaration UTF-8 string literals using the u8 modifier.


Question: How many programming languages are there as of April 2019?

C (programming language)

16-bit and 32-bit strings can be used to store UTF-16 and UTF-32 encodings if the uchar.h header file has __STDC_UTF_16__ and __STDC_UTF_32__ macro definitions, respectively.


Question: How many programming languages are there as of April 2019?

C (programming language)

Modifiers are used to specify string literals in these formats: u for 16-bit strings and U for 32-bit strings.


Question: How many programming languages are there as of April 2019?

C (programming language)

Examples of declaring string literals for multibyte strings:


Question: How many programming languages are there as of April 2019?

C (programming language)

const char *s8 = u8"UTF-8" multibyte string;


Question: How many programming languages are there as of April 2019?

C (programming language)

const char16_t *s16 = u"16-bit multibyte string”;


Question: How many programming languages are there as of April 2019?

C (programming language)

const char32_t *s32 = u"32-bit multibyte string”;


Question: How many programming languages are there as of April 2019?

C (programming language)

Keep in mind that the c16rtomb () function for converting from a 16-bit string to a multibyte string does not work as intended, and in the C11 standard was unable to translate from UTF-16 to UTF-8 [ 17].


Question: How many programming languages are there as of April 2019?

C (programming language)

The fix for this function may depend on the specific implementation of the compiler.


Question: How many programming languages are there as of April 2019?

C (programming language)

Custom types


Question: How many programming languages are there as of April 2019?

C (programming language)

Enumerations (enum)


Question: How many programming languages are there as of April 2019?

C (programming language)

Enumerations are a collection of named integer constants and are denoted by the enum keyword.


Question: How many programming languages are there as of April 2019?

C (programming language)

If a constant does not match a number, it is automatically set to either 0 for the first constant in the list, or a number one higher than the one specified in the previous constant.


Question: How many programming languages are there as of April 2019?

C (programming language)

At the same time, the enumeration data type itself can actually correspond to any signed or unfamiliar primitive type, in the range of which all the values of the enumerations fit; the decision to choose one or another type is accepted by the compiler.


Question: How many programming languages are there as of April 2019?

C (programming language)

However, explicit values for constants must be int [3] expressions.


Question: How many programming languages are there as of April 2019?

C (programming language)

The enumeration type can also be anonymous if the name of the enumeration is not specified.


Question: How many programming languages are there as of April 2019?

C (programming language)

It should be noted that constants specified in two different enumerations refer to two different data types, regardless of whether the enumerations are named or anonymous.


Question: How many programming languages are there as of April 2019?

C (programming language)

In practice, enumerations are often used to denote the states of finite automata, to specify options for operating modes or parameter values [18], to create integer constants, as well as for enumerating any unique objects or properties [19].


Question: How many programming languages are there as of April 2019?

C (programming language)

Structs (struct)


Question: How many programming languages are there as of April 2019?

C (programming language)

Structures are the combination of variables of different types of data within the same memory area; they are denoted by the struct keyword.


Question: How many programming languages are there as of April 2019?

C (programming language)

Variables within a structure are called structure fields.


Question: How many programming languages are there as of April 2019?

C (programming language)

From the point of view of address space, fields always follow each other in the same order in which they are specified, but compilers can align field addresses to optimize for a particular architecture.


Question: How many programming languages are there as of April 2019?

C (programming language)

Thus, in fact, the field can occupy a larger size than specified in the program.


Question: How many programming languages are there as of April 2019?

C (programming language)

Each field has a certain offset from the structure address and size.


Question: How many programming languages are there as of April 2019?

C (programming language)

The offset can be obtained using the offsetof () macro from the stddef.h header file.


Question: How many programming languages are there as of April 2019?

C (programming language)

At the same time, the offset will depend on the alignment and size of the previous fields.


Question: How many programming languages are there as of April 2019?

C (programming language)

The field size is usually determined by the alignment of the structure: if the field's data type alignment size is smaller than the structure alignment value, the field size is determined by the structure alignment.


Question: How many programming languages are there as of April 2019?

C (programming language)

Data type alignment can be obtained using the alignof () macro from the stdalign.h header file.


Question: How many programming languages are there as of April 2019?

C (programming language)

The size of the structure itself is the total size of all its margins, taking into account the alignment.


Question: How many programming languages are there as of April 2019?

C (programming language)

At the same time, some compilers provide special attributes that allow you to pack structures, removing alignments from them [20].


Question: How many programming languages are there as of April 2019?

C (programming language)

Structure fields can be explicitly assigned a colon-separated bit size after the field is defined and the number of bits is specified, which limits the range of their possible values, regardless of the field type.


Question: How many programming languages are there as of April 2019?

C (programming language)

This approach can be used as an alternative to flags and bitmasks to refer to them.


Question: How many programming languages are there as of April 2019?

C (programming language)

However, specifying the number of bits does not negate the possible alignment of the fields of structures in memory.


Question: How many programming languages are there as of April 2019?

C (programming language)

Working with bit fields has a number of limitations: it is impossible to apply the sizeof operator or the alignof () macro to them, and it is impossible to get a pointer to them.


Question: How many programming languages are there as of April 2019?

C (programming language)

Associations (union)


Question: How many programming languages are there as of April 2019?

C (programming language)

Associations are useful when you want to refer to the same variable as different data types; they are denoted by the union keyword.


Question: How many programming languages are there as of April 2019?

C (programming language)

An arbitrary number of overlapping fields can be declared inside the union, which in fact provide access to the same memory area as different data types.


Question: How many programming languages are there as of April 2019?

C (programming language)

The compiler selects the merge size based on the size of the largest field in the union.


Question: How many programming languages are there as of April 2019?

C (programming language)

Keep in mind that changing one join field changes all other fields, but only the value of the field that changed is guaranteed to be correct.


Question: How many programming languages are there as of April 2019?

C (programming language)

Joins can serve as a more convenient alternative to converting a pointer to an arbitrary type.


Question: How many programming languages are there as of April 2019?

C (programming language)

For example, using a union placed in a structure, you can create objects with a dynamically changing data type:


Question: How many programming languages are there as of April 2019?

C (programming language)

1 enum value_type_t {


Question: How many programming languages are there as of April 2019?

C (programming language)

2 VALUE_TYPE_LONG,//integer


Question: How many programming languages are there as of April 2019?

C (programming language)

3 VALUE_TYPE_DOUBLE,//real number


Question: How many programming languages are there as of April 2019?

C (programming language)

4 VALUE_TYPE_STRING,//string


Question: How many programming languages are there as of April 2019?

C (programming language)

5 VALUE_TYPE_BINARY,//arbitrary data


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

8 struct binary_t {


Question: How many programming languages are there as of April 2019?

C (programming language)

9 void *data;//data pointer


Question: How many programming languages are there as of April 2019?

C (programming language)

10 size_t data_size;//data size


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

13 struct string_t {


Question: How many programming languages are there as of April 2019?

C (programming language)

14 char *str;//pointer to a string


Question: How many programming languages are there as of April 2019?

C (programming language)

15 size_t str_size;//row size


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

18 union value_contents_t {


Question: How many programming languages are there as of April 2019?

C (programming language)

19 long as_long;//value as integer


Question: How many programming languages are there as of April 2019?

C (programming language)

20 double as_double;//value as real number


Question: How many programming languages are there as of April 2019?

C (programming language)

21 struct string_t as_string;//value as string


Question: How many programming languages are there as of April 2019?

C (programming language)

22 struct binary_t as_binary;//value as arbitrary data


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

25 struct value_t {


Question: How many programming languages are there as of April 2019?

C (programming language)

26 enum value_type_t type;//value type


Question: How many programming languages are there as of April 2019?

C (programming language)

27 union value_contents_t contents;//value content


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

Arrays


Question: How many programming languages are there as of April 2019?

C (programming language)

Arrays in the C language are primitive and are only a syntactic abstraction over pointer arithmetic.


Question: How many programming languages are there as of April 2019?

C (programming language)

The array itself is a pointer to a memory area, so all information about the size of the array and its boundaries can be accessed only at the compilation stage according to the type description.


Question: How many programming languages are there as of April 2019?

C (programming language)

Arrays can be either one-dimensional or multidimensional, but accessing an array element is reduced to simply calculating the offset from the origin address of the array.


Question: How many programming languages are there as of April 2019?

C (programming language)

Since arrays are based on address arithmetic, it is possible to work with them without using indexes.


Question: How many programming languages are there as of April 2019?

C (programming language)

For example, the following two examples of reading 10 numbers from an input stream are identical to each other:


Question: How many programming languages are there as of April 2019?

C (programming language)

The C language does not provide for any control over going beyond the array, so the programmer must monitor the work with arrays himself.


Question: How many programming languages are there as of April 2019?

C (programming language)

Errors when processing arrays do not always clearly affect the course of program execution, but can lead to segmentation errors and vulnerabilities.


Question: How many programming languages are there as of April 2019?

C (programming language)

Defining alternative names


Question: How many programming languages are there as of April 2019?

C (programming language)

The C language allows you to create your own type names using the typedef operator.


Question: How many programming languages are there as of April 2019?

C (programming language)

Alternate names can be given to both system types and custom types.


Question: How many programming languages are there as of April 2019?

C (programming language)

Such names are declared in the global namespace and do not conflict with the names of types of structures, enumerations, and unions.


Question: How many programming languages are there as of April 2019?

C (programming language)

Alternative names can be used both to simplify the code and to create levels of abstraction.


Question: How many programming languages are there as of April 2019?

C (programming language)

For example, some system types can be shortened to improve code readability or unify code writing in user code: #include <stdint.h>


Question: How many programming languages are there as of April 2019?

C (programming language)

typedef int32_t i32_t;


Question: How many programming languages are there as of April 2019?

C (programming language)

typedef int_fast32_t i32fast_t;


Question: How many programming languages are there as of April 2019?

C (programming language)

typedef int_least32_t i32least_t;


Question: How many programming languages are there as of April 2019?

C (programming language)

typedef uint32_t u32_t;


Question: How many programming languages are there as of April 2019?

C (programming language)

typedef uint_fast32_t u32fast_t;


Question: How many programming languages are there as of April 2019?

C (programming language)

typedef uint_least32_t u32least_t;


Question: How many programming languages are there as of April 2019?

C (programming language)

An example of abstraction is the type names in operating system header files.


Question: How many programming languages are there as of April 2019?

C (programming language)

For example, the POSIX standard defines the pid_t type, which is used to store a numeric process identifier.


Question: How many programming languages are there as of April 2019?

C (programming language)

In fact, this type is an alternative name for some primitive type, for example: typedef int __kernel_pid_t;


Question: How many programming languages are there as of April 2019?

C (programming language)

typedef __kernel_pid_t __pid_t


Question: How many programming languages are there as of April 2019?

C (programming language)

typedef __pid_t pid_t;


Question: How many programming languages are there as of April 2019?

C (programming language)

Since types with alternative names are only synonymous with the original types, they remain fully compatible and interchangeable.


Question: How many programming languages are there as of April 2019?

C (programming language)

Preprocessor


Question: How many programming languages are there as of April 2019?

C (programming language)

The preprocessor works before compilation and converts the text of the program file according to the directives encountered in it or passed to the preprocessor.


Question: How many programming languages are there as of April 2019?

C (programming language)

Technically, the preprocessor can be implemented in different ways, but logically it is convenient to represent it as a separate module that processes each file intended for compilation and forms text that then gets to the compiler's input.


Question: How many programming languages are there as of April 2019?

C (programming language)

The preprocessor looks for lines in the text that begin with the # character, followed by the preprocessor directives.


Question: How many programming languages are there as of April 2019?

C (programming language)

Everything that is not related to preprocessor directives and is not excluded from compilation according to the directives is passed to the compiler's input unchanged.


Question: How many programming languages are there as of April 2019?

C (programming language)

The preprocessor features include:


Question: How many programming languages are there as of April 2019?

C (programming language)

substituting a given token with text using the #define directive, including the ability to create parameterized text templates (called similarly to functions), as well as cancel such substitutions, which gives the ability to replace the program text in limited areas;


Question: How many programming languages are there as of April 2019?

C (programming language)

Conditionally embed and remove parts of text, including the directives themselves, using the conditional commands #ifdef, #ifndef, #if, #else and #endif;


Question: How many programming languages are there as of April 2019?

C (programming language)

embedding text from another file into the current file using the #include directive.


Question: How many programming languages are there as of April 2019?

C (programming language)

It is important to understand that the preprocessor only provides text substitution, without taking into account the syntax and semantics of the language.


Question: How many programming languages are there as of April 2019?

C (programming language)

For example, #define macro definitions can be found inside functions or type definitions, and conditional compilation directives can lead to the exclusion of any part of the program from the compiled text code, without regard to language grammar.


Question: How many programming languages are there as of April 2019?

C (programming language)

Macro definitions are often used to ensure compatibility with different versions of libraries that have changed their API, including certain code fragments depending on the library version.


Question: How many programming languages are there as of April 2019?

C (programming language)

For this purpose, libraries often provide macro definitions describing their version [21], and sometimes macros with parameters to compare the current version with the one specified within the preprocessor [22].


Question: How many programming languages are there as of April 2019?

C (programming language)

Macro definitions are also used for conditional compilation of individual parts of the program, for example, to enable support for some additional functionality.


Question: How many programming languages are there as of April 2019?

C (programming language)

Macro definitions with parameters are widely used in C programs to create analogues of generalized functions.


Question: How many programming languages are there as of April 2019?

C (programming language)

Previously, they were also used to implement embedded functions, but since the C99 standard, this need has disappeared due to the addition of inline functions.


Question: How many programming languages are there as of April 2019?

C (programming language)

However, due to the fact that macro definitions with parameters are not functions, but are called in the same way, unexpected problems may occur by mistake of the programmer, including working out only parts of the code from the macro definition [23] and incorrect priorities for performing operations [24].


Question: How many programming languages are there as of April 2019?

C (programming language)

An example of an erroneous code is the squaring macro:


Question: How many programming languages are there as of April 2019?

C (programming language)

1 #include <stdio.h>


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

3 int main (void)


Question: How many programming languages are there as of April 2019?

C (programming language)

4 {


Question: How many programming languages are there as of April 2019?

C (programming language)

5 #define SQR (x) x *x


Question: How many programming languages are there as of April 2019?

C (programming language)

6 printf (“%d”, SQR (5));//all right, 5*5=25


Question: How many programming languages are there as of April 2019?

C (programming language)

7 printf (“%d”, SQR (5+0));//was supposed to be 25, but 5 would be output (5+0*5+0)


Question: How many programming languages are there as of April 2019?

C (programming language)

8 printf (“%d”, SQR (4/3));//all right, 1 (because 4/3=1, 1*4=4, 4/3=1)


Question: How many programming languages are there as of April 2019?

C (programming language)

9 printf (“%d”, SQR (5/2));//expected 4 (2*2), but 5 (5/2*5/2) will be output


Question: How many programming languages are there as of April 2019?

C (programming language)

10 return 0;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

In the example above, the error is that the contents of the macro argument are inserted into the text as it is, without taking into account the priorities of operations.


Question: How many programming languages are there as of April 2019?

C (programming language)

In such cases, it is necessary to use inline functions or explicitly prioritize operations in expressions that use macro parameters using parentheses:


Question: How many programming languages are there as of April 2019?

C (programming language)

1 #include <stdio.h>


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

3 int main (void)


Question: How many programming languages are there as of April 2019?

C (programming language)

4 {


Question: How many programming languages are there as of April 2019?

C (programming language)

5 #define SQR (x) ((x) * (x))


Question: How many programming languages are there as of April 2019?

C (programming language)

6 printf (“%d”, SQR (4+1));//true, 25


Question: How many programming languages are there as of April 2019?

C (programming language)

7 return 0;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

C programming


Question: How many programming languages are there as of April 2019?

C (programming language)

Program structure


Question: How many programming languages are there as of April 2019?

C (programming language)

Modules


Question: How many programming languages are there as of April 2019?

C (programming language)

A program is a collection of C code files that can be compiled into object files.


Question: How many programming languages are there as of April 2019?

C (programming language)

The object files then go through a stage of linking to each other, as well as with external libraries, resulting in a final executable or library.


Question: How many programming languages are there as of April 2019?

C (programming language)

Linking files to each other, as well as libraries, requires a description of the prototypes of functions used, external variables, and the required data types in each file.


Question: How many programming languages are there as of April 2019?

C (programming language)

It is customary to place such data in separate header files, which are connected using the #include directive in files where one or another functionality is required, and allow you to organize the system, similar to a module system.


Question: How many programming languages are there as of April 2019?

C (programming language)

In this case, the module can be:


Question: How many programming languages are there as of April 2019?

C (programming language)

a set of separate source code files, for which the interface is presented in the form of header files;


Question: How many programming languages are there as of April 2019?

C (programming language)

an object library or part of it, with corresponding header files;


Question: How many programming languages are there as of April 2019?

C (programming language)

a self-contained set of one or more header files (front-end library);


Question: How many programming languages are there as of April 2019?

C (programming language)

a static library or part of it with corresponding header files;


Question: How many programming languages are there as of April 2019?

C (programming language)

a dynamic library or part of it with corresponding header files.


Question: How many programming languages are there as of April 2019?

C (programming language)

Since the #include directive only substitutes the text of another file at the preprocessor stage, multiple attachments of the same file can lead to compile errors.


Question: How many programming languages are there as of April 2019?

C (programming language)

Therefore, these files use protection against re-inclusion using the #define and #ifndef macros.


Question: How many programming languages are there as of April 2019?

C (programming language)

Source code files


Question: How many programming languages are there as of April 2019?

C (programming language)

The C source file text consists of a set of global definitions of data, types, and functions.


Question: How many programming languages are there as of April 2019?

C (programming language)

Global variables and functions declared with static and inline specifiers are available only within the file in which they are declared, or when one file is included in another through a directive #include.


Question: How many programming languages are there as of April 2019?

C (programming language)

At the same time, functions and variables declared in the header file with the word static will be re-created each time the header file is attached to another source file.


Question: How many programming languages are there as of April 2019?

C (programming language)

Global variables and function prototypes declared with the extern specifier are considered pluggable from other files.


Question: How many programming languages are there as of April 2019?

C (programming language)

That is, they are allowed to be used as described; it is assumed that after the program is built, they will be linked by the linker to the original objects and functions described in their files.


Question: How many programming languages are there as of April 2019?

C (programming language)

Global variables and functions other than static and inline can be accessed from files other than static, provided they are properly declared there with the extern specifier.


Question: How many programming languages are there as of April 2019?

C (programming language)

Variables and functions declared with the static modifier can also be accessed in other files, but only by passing their address by pointer.


Question: How many programming languages are there as of April 2019?

C (programming language)

Typedef, struct, and union declarations cannot be imported in other files.


Question: How many programming languages are there as of April 2019?

C (programming language)

If it is necessary to use them in other files, they must be duplicated there, or placed in a separate header file.


Question: How many programming languages are there as of April 2019?

C (programming language)

The same applies to inline functions.


Question: How many programming languages are there as of April 2019?

C (programming language)

Program entry point


Question: How many programming languages are there as of April 2019?

C (programming language)

For an executable program, the standard entry point is a function named main, which cannot be static and must be the only one in the program.


Question: How many programming languages are there as of April 2019?

C (programming language)

The program execution starts with the first statement of the main () function and continues until it exits, after which the program ends and returns the abstract integer code to the operating system the result of their work.


Question: How many programming languages are there as of April 2019?

C (programming language)

Valid function prototypes are as follows [3]:


Question: How many programming languages are there as of April 2019?

C (programming language)

When called, the argc variable is passed the number of arguments passed to the program, including the path to the program itself, so the argc variable usually contains a value of at least 1.


Question: How many programming languages are there as of April 2019?

C (programming language)

The argv variable is passed to the program launch string itself as an array of text strings, the last element of which is NULL.


Question: How many programming languages are there as of April 2019?

C (programming language)

The compiler ensures that when the main () function is run, all global variables in the program will be initialized.


Question: How many programming languages are there as of April 2019?

C (programming language)

As a result, the main () function can return any integer in a range of int values that will be passed to the operating system as a program return code.


Question: How many programming languages are there as of April 2019?

C (programming language)

The language standard does not determine the meaning of return codes.


Question: How many programming languages are there as of April 2019?

C (programming language)

Usually, the operating system where the programs run has some means to get the value of the return code and analyze it.


Question: How many programming languages are there as of April 2019?

C (programming language)

Sometimes there are certain conventions about the meaning of these codes.


Question: How many programming languages are there as of April 2019?

C (programming language)

A common convention is that a zero value of the return code signals the successful completion of the program, and a non-zero value is the code of the error that occurred.


Question: How many programming languages are there as of April 2019?

C (programming language)

Return codes can also be used within multi-process applications to ensure interaction between these processes, in which case the application detects itself meaning for each return code.


Question: How many programming languages are there as of April 2019?

C (programming language)

Working with memory


Question: How many programming languages are there as of April 2019?

C (programming language)

Data storage


Question: How many programming languages are there as of April 2019?

C (programming language)

One of the most important functions of any programming language is to provide the ability to manage memory and the objects stored in it.


Question: How many programming languages are there as of April 2019?

C (programming language)

C has three different ways of allocating memory (memory classes) for objects:


Question: How many programming languages are there as of April 2019?

C (programming language)

Static memory allocation: space for objects is created in the program data segment at the time of compilation; the lifetime of such objects coincides with the lifetime of this code.


Question: How many programming languages are there as of April 2019?

C (programming language)

Changing such objects leads to what is called “undefined behavior” in the standard (English: undefined behavior).


Question: How many programming languages are there as of April 2019?

C (programming language)

In practice, this operation may result in an error at runtime.


Question: How many programming languages are there as of April 2019?

C (programming language)

Automatic memory allocation: objects can be stored on the stack; this memory is then automatically released and can be used again after the program leaves the block that uses it.


Question: How many programming languages are there as of April 2019?

C (programming language)

Dynamic memory allocation: memory blocks of the right size can be requested during program execution using the library functions malloc (), realloc (), calloc () from a memory area called a bunch.


Question: How many programming languages are there as of April 2019?

C (programming language)

These blocks are released and can be used again after calling the free () function for them.


Question: How many programming languages are there as of April 2019?

C (programming language)

All three of these ways of storing data are suitable for different situations and have advantages and disadvantages.


Question: How many programming languages are there as of April 2019?

C (programming language)

For example, static memory allocation has no allocation overhead, automatic allocation is only a small allocation cost, but dynamic allocation potentially requires large the costs of both allocating and releasing memory.


Question: How many programming languages are there as of April 2019?

C (programming language)

On the other hand, stack memory is much more limited than static or heap memory.


Question: How many programming languages are there as of April 2019?

C (programming language)

Only dynamic memory can be used in cases where the size of the objects used is not known in advance.


Question: How many programming languages are there as of April 2019?

C (programming language)

Most C programs use all three of these methods intensively.


Question: How many programming languages are there as of April 2019?

C (programming language)

Where possible, automatic or static memory allocation is preferable: this method of storing objects is controlled by the compiler, which frees the programmer from the difficulties of manual allocating and releasing memory, which usually serves as a source of hard-to-find errors of memory leaks and re-freeing in the program.


Question: How many programming languages are there as of April 2019?

C (programming language)

Unfortunately, many data structures are variable in size during program execution, so due to the fact that automatically and statically allocated areas must have a known fixed size at compile time, it is very common to use dynamic selection.


Question: How many programming languages are there as of April 2019?

C (programming language)

Variable-sized arrays are the most common example of such memory usage.


Question: How many programming languages are there as of April 2019?

C (programming language)

Memory addressing


Question: How many programming languages are there as of April 2019?

C (programming language)

The C language has inherited linear memory addressing when working with structures, arrays, and dedicated memory areas.


Question: How many programming languages are there as of April 2019?

C (programming language)

The language standard also allows comparison operations to be performed on a null pointer and on addresses within arrays, structures, and allocated memory areas.


Question: How many programming languages are there as of April 2019?

C (programming language)

It is also possible to work with the address of the array element following the last one, which is done to facilitate writing algorithms.


Question: How many programming languages are there as of April 2019?

C (programming language)

However, the comparison of address pointers obtained for different variables (or memory regions) should not be carried out, as the result will depend on the implementation of a particular compiler [25].


Question: How many programming languages are there as of April 2019?

C (programming language)

Representation in memory


Question: How many programming languages are there as of April 2019?

C (programming language)

This section discusses the in-memory representation of the program in the GNU/Linux operating system and the amd64 architecture.


Question: How many programming languages are there as of April 2019?

C (programming language)

The order of the heap, stack, and other regions may differ across architectures and operating systems.


Question: How many programming languages are there as of April 2019?

C (programming language)

When the program is started, processor instructions (machine code) and initialized data are imported from the executable file into RAM.


Question: How many programming languages are there as of April 2019?

C (programming language)

At the same time, command-line arguments (available in the main () function with the following signature in the second int argc argument, char ** argv) and environment variables are imported into high addresses.


Question: How many programming languages are there as of April 2019?

C (programming language)

The initialized data area stores immutable data.


Question: How many programming languages are there as of April 2019?

C (programming language)

This could be string literals, for example.


Question: How many programming languages are there as of April 2019?

C (programming language)

Global variables are stored in the scope of uninitialized data.


Question: How many programming languages are there as of April 2019?

C (programming language)

During the startup process, this area is initially initialized to zero values.


Question: How many programming languages are there as of April 2019?

C (programming language)

Dynamically allocated memory is provided from the heap.


Question: How many programming languages are there as of April 2019?

C (programming language)

The malloc () function from stdlib.h is used to allocate memory while the program is running.


Question: How many programming languages are there as of April 2019?

C (programming language)

For release, the free () function.


Question: How many programming languages are there as of April 2019?

C (programming language)

The stack area is designed to accommodate function calls.


Question: How many programming languages are there as of April 2019?

C (programming language)

Each time a function is called, the stack increases.


Question: How many programming languages are there as of April 2019?

C (programming language)

After the function has completed its work, the stack is reduced.


Question: How many programming languages are there as of April 2019?

C (programming language)

Functions declared with the inline qualifier may not use the stack, but be substituted into the code (the compiler is free to ignore inline).


Question: How many programming languages are there as of April 2019?

C (programming language)

Another important detail is the presence of random indentation between the stack and the top area, as well as between the initialized data area and the heap.


Question: How many programming languages are there as of April 2019?

C (programming language)

This is done for security reasons, for example, to prevent other features from being built into the stack.


Question: How many programming languages are there as of April 2019?

C (programming language)

Dynamic link libraries and file mapping from the filesystem are between the stack and the heap.


Question: How many programming languages are there as of April 2019?

C (programming language)

It is also worth considering that variables with the register qualifier are likely to be placed directly in the processor's memory (registers).


Question: How many programming languages are there as of April 2019?

C (programming language)

However, the number of registers is limited, so the compiler can ignore this recommendation.


Question: How many programming languages are there as of April 2019?

C (programming language)

There is no address capture operation for such variables.


Question: How many programming languages are there as of April 2019?

C (programming language)

Error handling


Question: How many programming languages are there as of April 2019?

C (programming language)

C does not have any built-in error control mechanisms, but there are several generally accepted ways to handle them using language tools.


Question: How many programming languages are there as of April 2019?

C (programming language)

In general, the practice of processing C errors in fault-tolerant code forces us to write cumbersome, often repetitive constructions in which the algorithm is combined with error processing.


Question: How many programming languages are there as of April 2019?

C (programming language)

Error markers and errno


Question: How many programming languages are there as of April 2019?

C (programming language)

The standard library actively uses the errno special variable from the errno.h header file, into which functions enter the error code, returning a value that is an error marker.


Question: How many programming languages are there as of April 2019?

C (programming language)

To check the result for errors, the result is compared with the error marker, and if they match, you can analyze the error code stored in errno to correct the program or output debug message.


Question: How many programming languages are there as of April 2019?

C (programming language)

The following values are usually used as error markers:


Question: How many programming languages are there as of April 2019?

C (programming language)

-1 for int type in cases where the negative result range is not used;


Question: How many programming languages are there as of April 2019?

C (programming language)

-1 for ssize_t type;


Question: How many programming languages are there as of April 2019?

C (programming language)

(size_t) -1 for size_t type;


Question: How many programming languages are there as of April 2019?

C (programming language)

NULL for pointers;


Question: How many programming languages are there as of April 2019?

C (programming language)

a non-zero error code.


Question: How many programming languages are there as of April 2019?

C (programming language)

The practice of returning an error marker instead of an error code, although it saves the number of arguments passed to functions, in some cases leads to errors as a result of the human factor.


Question: How many programming languages are there as of April 2019?

C (programming language)

For example, programmers often ignore checking a result of type ssize_t, and the result itself is used further in calculations, which leads to difficult to grasp errors if -1 is returned.


Question: How many programming languages are there as of April 2019?

C (programming language)

Returning the correct value as an error marker [26] contributes even more to the appearance of errors, which also forces the programmer to do more checks and, accordingly, write more of the same type repetitive code.


Question: How many programming languages are there as of April 2019?

C (programming language)

This approach is practiced in stream functions that work with objects of the FILE* type: the error marker is the EOF value, while it is also an end-of-file marker.


Question: How many programming languages are there as of April 2019?

C (programming language)

Therefore, EOF sometimes has to check the character stream both at the end of the file using the feof () function and for an error using the ferror () [27] function.


Question: How many programming languages are there as of April 2019?

C (programming language)

At the same time, some functions that can return EOF by standard are not required to set errno.


Question: How many programming languages are there as of April 2019?

C (programming language)

The lack of common error handling practices in the standard library leads to the emergence of its own methods of error handling and the combination of commonly used methods in third-party projects.


Question: How many programming languages are there as of April 2019?

C (programming language)

For example, the systemd project combined the idea of returning an error code and the number -1 as a marker — a negative error code is returned [28].


Question: How many programming languages are there as of April 2019?

C (programming language)

And the GLib library introduced the practice of returning a Boolean value as an error marker, while detailed information about the error is placed in a special structure, the pointer to which is returned through the last argument of the function [29].


Question: How many programming languages are there as of April 2019?

C (programming language)

A similar solution is used by the Enlightenment project, which also uses the Boolean type as a marker, but the error information is returned by analogy with the standard library — through a separate function [30] that should be checked if a token is returned.


Question: How many programming languages are there as of April 2019?

C (programming language)

Returning an error code


Question: How many programming languages are there as of April 2019?

C (programming language)

An alternative to error markers is to return the error code directly, and the result of the function's work through pointer arguments.


Question: How many programming languages are there as of April 2019?

C (programming language)

This is the path taken by the developers of the POSIX standard, in whose functions it is customary to return an error code as an int number.


Question: How many programming languages are there as of April 2019?

C (programming language)

However, returning an int value clearly does not make it clear that it is the error code that is returned, and not the token, which can lead to errors if the result of such functions is checked for -1.


Question: How many programming languages are there as of April 2019?

C (programming language)

Extension K of the C11 standard introduces a special errno_t type for storing an error code.


Question: How many programming languages are there as of April 2019?

C (programming language)

There are recommendations to use this type in user code to return errors, and if it is not provided by the standard library, declare it yourself [31]: #ifndef __STDC_LIB_EXT1__


Question: How many programming languages are there as of April 2019?

C (programming language)

typedef int errno_t;


Question: How many programming languages are there as of April 2019?

C (programming language)

#endif


Question: How many programming languages are there as of April 2019?

C (programming language)

This approach, in addition to improving the code quality, eliminates the need to use errno, which allows you to make libraries with reentrable functions without the need to connect additional libraries such as POSIX Threads to correctly define errno.


Question: How many programming languages are there as of April 2019?

C (programming language)

Errors in math functions


Question: How many programming languages are there as of April 2019?

C (programming language)

It is more difficult to handle errors in mathematical functions from the math.h header file, in which 3 types of errors can occur [32]:


Question: How many programming languages are there as of April 2019?

C (programming language)

going beyond the range of input values;


Question: How many programming languages are there as of April 2019?

C (programming language)

getting an infinite result for the final input data;


Question: How many programming languages are there as of April 2019?

C (programming language)

the result is outside the range of the data type used.


Question: How many programming languages are there as of April 2019?

C (programming language)

Preventing two of the three types of errors comes down to checking the input data for the range of acceptable values.


Question: How many programming languages are there as of April 2019?

C (programming language)

However, it is extremely difficult to predict whether the result will go beyond the type.


Question: How many programming languages are there as of April 2019?

C (programming language)

Therefore, the language standard provides for the ability to analyze mathematical functions for errors.


Question: How many programming languages are there as of April 2019?

C (programming language)

Starting with the C99 standard, this analysis is possible in two ways, depending on the value stored in the math_errhandling macro.


Question: How many programming languages are there as of April 2019?

C (programming language)

If the MATH_ERRNO bit is set, the errno variable must first be reset to 0, and after calling the mathematical function, check for EDOM and ERANGE errors.


Question: How many programming languages are there as of April 2019?

C (programming language)

If the MATH_ERREXCEPT bit is set, possible mathematical errors are first cleared by the feclearexcept () function from the fenv.h header file, and tested after calling the math function using the fetestexcept () function.


Question: How many programming languages are there as of April 2019?

C (programming language)

At the same time, the method of error handling is determined by a specific implementation of the standard library and may not be available


Question: How many programming languages are there as of April 2019?

C (programming language)

Therefore, in platform-independent code, it may be necessary to check the result in two ways at once, depending on the math_errhandling value [32].


Question: How many programming languages are there as of April 2019?

C (programming language)

Releasing resources


Question: How many programming languages are there as of April 2019?

C (programming language)

As a rule, the occurrence of an error requires the function to close and the error indicator returns.


Question: How many programming languages are there as of April 2019?

C (programming language)

If an error in a function can occur in different parts of it, it is necessary to free up resources allocated during its operation to prevent leaks.


Question: How many programming languages are there as of April 2019?

C (programming language)

It is a good practice to free up resources in reverse order before returning from the function, and in case of errors, releasing them in reverse order after the main return.


Question: How many programming languages are there as of April 2019?

C (programming language)

Some parts of this release can be made using the goto operator [33].


Question: How many programming languages are there as of April 2019?

C (programming language)

This approach makes it possible to take code fragments not related to the algorithm being implemented outside the algorithm itself, increasing the readability of the code, and is similar to the work of the defer operator from the Go programming language.


Question: How many programming languages are there as of April 2019?

C (programming language)

An example of freeing up resources is provided below in the examples section.


Question: How many programming languages are there as of April 2019?

C (programming language)

To free up resources, the program provides a mechanism for program exit handlers.


Question: How many programming languages are there as of April 2019?

C (programming language)

Handlers are assigned using the atexit () function and are executed both at the end of the main () function through the return operator and after the exit () function is executed.


Question: How many programming languages are there as of April 2019?

C (programming language)

At the same time, handlers are not executed by abort () and _Exit () functions [34].


Question: How many programming languages are there as of April 2019?

C (programming language)

As an example of releasing resources at the end of the program, we can cite the release of memory allocated for global variables.


Question: How many programming languages are there as of April 2019?

C (programming language)

Despite the fact that memory is somehow freed up when the operating system completes the program, it is allowed not to release the memory that is required throughout the entire operation of the program [35 ], explicit release is preferable, as it makes it easier to find memory leaks by third-party means and reduces the chance of memory leaks as a result of an error:


Question: How many programming languages are there as of April 2019?

C (programming language)

1 #include <stdio.h>


Question: How many programming languages are there as of April 2019?

C (programming language)

2 #include <stdlib.h>


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

4 int numbers_count;


Question: How many programming languages are there as of April 2019?

C (programming language)

5 int *numbers;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

7 void free_numbers (void)


Question: How many programming languages are there as of April 2019?

C (programming language)

8 {


Question: How many programming languages are there as of April 2019?

C (programming language)

9 free (numbers);


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

12 int main (int argc, char **argv)


Question: How many programming languages are there as of April 2019?

C (programming language)

13 {


Question: How many programming languages are there as of April 2019?

C (programming language)

14 if (argc < 2) {


Question: How many programming languages are there as of April 2019?

C (programming language)

15 exit (EXIT_FAILURE);


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

17 numbers_count = atoi (argv [1])


Question: How many programming languages are there as of April 2019?

C (programming language)

18 if (numbers_count <= 0) {


Question: How many programming languages are there as of April 2019?

C (programming language)

19 exit (EXIT_FAILURE);


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

22 numbers = calloc (numbers_count, sizeof (*numbers));


Question: How many programming languages are there as of April 2019?

C (programming language)

23 if (! numbers) {


Question: How many programming languages are there as of April 2019?

C (programming language)

24 perror (“Error allocating memory for array”);


Question: How many programming languages are there as of April 2019?

C (programming language)

25 exit (EXIT_FAILURE);


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

27 atexit (free_numbers);


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

29//... working with numbers array


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

31//The free_numbers () handler will be automatically called here


Question: How many programming languages are there as of April 2019?

C (programming language)

32 return EXIT_SUCCESS;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

The disadvantage of this approach is that the format of the handlers to be assigned does not provide for the transfer of arbitrary data to the function, which allows you to create handlers only for global variables.


Question: How many programming languages are there as of April 2019?

C (programming language)

Examples of C programs


Question: How many programming languages are there as of April 2019?

C (programming language)

Simplest C program


Question: How many programming languages are there as of April 2019?

C (programming language)

The simplest C program looks like this:


Question: How many programming languages are there as of April 2019?

C (programming language)

int main (void)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

It is allowed not to write a return statement for the main () function.


Question: How many programming languages are there as of April 2019?

C (programming language)

In this case, according to the standard, the main () function returns 0, executing all the handlers assigned to the exit () function.


Question: How many programming languages are there as of April 2019?

C (programming language)

This implies that the program has been successfully completed [14].


Question: How many programming languages are there as of April 2019?

C (programming language)

Hello, world!


Question: How many programming languages are there as of April 2019?

C (programming language)

Hello, world!


Question: How many programming languages are there as of April 2019?

C (programming language)

is given in the first edition of Kernigan and Ritchie's C Programming Language:


Question: How many programming languages are there as of April 2019?

C (programming language)

#include <stdio.h>


Question: How many programming languages are there as of April 2019?

C (programming language)

int main (void)//Does not accept arguments


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

printf (“Hello, world!


Question: How many programming languages are there as of April 2019?

C (programming language)

\ n”);//'\ n' - new line


Question: How many programming languages are there as of April 2019?

C (programming language)

return 0;//Successful completion of the program


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

This program prints the message “Hello, world!” on a standard output device.


Question: How many programming languages are there as of April 2019?

C (programming language)

Error handling by reading a file


Question: How many programming languages are there as of April 2019?

C (programming language)

Many C functions can return an error without doing what they are required to do.


Question: How many programming languages are there as of April 2019?

C (programming language)

Errors need to be checked and responded to correctly, including often pushing the error from the function to a higher level for analysis.


Question: How many programming languages are there as of April 2019?

C (programming language)

At the same time, the function in which the error occurred can be made reentrable, in which case the function should not change the input or output data by mistake, which allows you to safely restart it after correcting an erroneous situation.


Question: How many programming languages are there as of April 2019?

C (programming language)

The example implements the C file read function, but it requires that the fopen () and fread () functions comply with the POSIX standard, otherwise they may not set the errno variable, which greatly complicates both debugging, and writing universal and safe code.


Question: How many programming languages are there as of April 2019?

C (programming language)

On platforms that do not comply with POSIX, the behavior of this program will be undefined in the event of an error.


Question: How many programming languages are there as of April 2019?

C (programming language)

1 #include <errno.h>


Question: How many programming languages are there as of April 2019?

C (programming language)

2 #include <stdio.h>


Question: How many programming languages are there as of April 2019?

C (programming language)

3 #include <stdlib.h>


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

5//Determine the type to store the error code if it is not defined


Question: How many programming languages are there as of April 2019?

C (programming language)

6 #ifndef __STDC_LIB_EXT1__


Question: How many programming languages are there as of April 2019?

C (programming language)

7 typedef int errno_t;


Question: How many programming languages are there as of April 2019?

C (programming language)

8 #endif


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

10//Read file content function


Question: How many programming languages are there as of April 2019?

C (programming language)

11 errno_t get_file_contents (const char *filename,


Question: How many programming languages are there as of April 2019?

C (programming language)

12 void **contents_ptr,


Question: How many programming languages are there as of April 2019?

C (programming language)

13 size_t *contents_size_ptr)


Question: How many programming languages are there as of April 2019?

C (programming language)

14 {


Question: How many programming languages are there as of April 2019?

C (programming language)

15 FILE *f;


Question: How many programming languages are there as of April 2019?

C (programming language)

16 f = fopen (filename, “rb”);


Question: How many programming languages are there as of April 2019?

C (programming language)

17 if (! f) {


Question: How many programming languages are there as of April 2019?

C (programming language)

18//In POSIX, fopen () sets errno by error


Question: How many programming languages are there as of April 2019?

C (programming language)

19 return errno;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

22//Get file size


Question: How many programming languages are there as of April 2019?

C (programming language)

23 fseek (f, 0, SEEK_END);


Question: How many programming languages are there as of April 2019?

C (programming language)

24 long contents_size = ftell (f);


Question: How many programming languages are there as of April 2019?

C (programming language)

25 if (contents_size == 0) {


Question: How many programming languages are there as of April 2019?

C (programming language)

26 *contents_ptr = NULL;


Question: How many programming languages are there as of April 2019?

C (programming language)

27 *contents_size_ptr = 0;


Question: How many programming languages are there as of April 2019?

C (programming language)

28 goto cleaning_fopen;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

30 rewind (f);


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

32//Variable for storing the returned error code


Question: How many programming languages are there as of April 2019?

C (programming language)

33 errno_t saved_errno;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

35 void *contents;


Question: How many programming languages are there as of April 2019?

C (programming language)

36 contents = malloc (contents_size);


Question: How many programming languages are there as of April 2019?

C (programming language)

37 if (! contents) {


Question: How many programming languages are there as of April 2019?

C (programming language)

38 saved_errno = errno;


Question: How many programming languages are there as of April 2019?

C (programming language)

39 goto aborting_fopen;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

42//Read the entire file at the contents pointer


Question: How many programming languages are there as of April 2019?

C (programming language)

43 size_t n;


Question: How many programming languages are there as of April 2019?

C (programming language)

44 n = fread (contents, contents_size, 1, f);


Question: How many programming languages are there as of April 2019?

C (programming language)

45 if (n == 0) {


Question: How many programming languages are there as of April 2019?

C (programming language)

46//Don't check for feof () because it's buffered after fseek ()


Question: How many programming languages are there as of April 2019?

C (programming language)

47//In POSIX fread () sets errno by error


Question: How many programming languages are there as of April 2019?

C (programming language)

48 saved_errno = errno;


Question: How many programming languages are there as of April 2019?

C (programming language)

49 goto aborting_contents;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

52//Returning the allocated memory and its size


Question: How many programming languages are there as of April 2019?

C (programming language)

53 *contents_ptr = contents;


Question: How many programming languages are there as of April 2019?

C (programming language)

54 *contents_size_ptr = contents_size;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

56//Resource release section upon successful completion


Question: How many programming languages are there as of April 2019?

C (programming language)

57 cleaning_fopen:


Question: How many programming languages are there as of April 2019?

C (programming language)

58 fclose (f);


Question: How many programming languages are there as of April 2019?

C (programming language)

59 return 0;//0 - successful execution


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

61//Separate section to release resources by mistake


Question: How many programming languages are there as of April 2019?

C (programming language)

62 aborting_contents:


Question: How many programming languages are there as of April 2019?

C (programming language)

63 free (contents);


Question: How many programming languages are there as of April 2019?

C (programming language)

64 aborting_fopen:


Question: How many programming languages are there as of April 2019?

C (programming language)

65 fclose (f);


Question: How many programming languages are there as of April 2019?

C (programming language)

66 return saved_errno;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

69 int main (int argc, char **argv)


Question: How many programming languages are there as of April 2019?

C (programming language)

70 {


Question: How many programming languages are there as of April 2019?

C (programming language)

71 if (argc < 2) {


Question: How many programming languages are there as of April 2019?

C (programming language)

72 return EXIT_FAILURE;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

74 const char *filename = argv [1];


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

76 errno_t errnum;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

78 void *contents;


Question: How many programming languages are there as of April 2019?

C (programming language)

79 size_t contents_size;


Question: How many programming languages are there as of April 2019?

C (programming language)

80 errnum = get_file_contents (filename, &contents, &contents_size);


Question: How many programming languages are there as of April 2019?

C (programming language)

81 if (errnum) {


Question: How many programming languages are there as of April 2019?

C (programming language)

82 char buf [1024];


Question: How many programming languages are there as of April 2019?

C (programming language)

83 const char *error_text = streror_r (errnum, buf, sizeof (buf));


Question: How many programming languages are there as of April 2019?

C (programming language)

84 fprintf (stderr, “%s\ n”, error_text);


Question: How many programming languages are there as of April 2019?

C (programming language)

85 exit (EXIT_FAILURE);


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

88 printf (“%. *s”, (int) contents_size, contents);


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

90 free (contents);


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

92 return EXIT_SUCCESS;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

Functional programming


Question: How many programming languages are there as of April 2019?

C (programming language)

An example of a program that uses so-called “higher-order functions” and “pure functions”:


Question: How many programming languages are there as of April 2019?

C (programming language)

1 #include <stdio.h>


Question: How many programming languages are there as of April 2019?

C (programming language)

2 #include <stdlib.h>


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

4 int add_one (const int) __attribute__ ((const));


Question: How many programming languages are there as of April 2019?

C (programming language)

5 int subtract_one (const int) __attribute__ ((const));


Question: How many programming languages are there as of April 2019?

C (programming language)

6 int modify (const int, int (*f) (const int));


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

8 int add_one (const int num) return num +1;


Question: How many programming languages are there as of April 2019?

C (programming language)

9 int subtract_one (const int num) return num - 1;


Question: How many programming languages are there as of April 2019?

C (programming language)

10 int modify (const int num, int (*f) (const int)) return f (num);


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

12 int main (void)


Question: How many programming languages are there as of April 2019?

C (programming language)

13 {


Question: How many programming languages are there as of April 2019?

C (programming language)

14 int num_1 = modify (10, * (add_one));


Question: How many programming languages are there as of April 2019?

C (programming language)

15 printf (“%d\ n”, num_1);//output: 11


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

17 num_1 = modify (10, * (subtract_one));


Question: How many programming languages are there as of April 2019?

C (programming language)

18 printf (“%d\ n”, num_1);//output: 9


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

20 return EXIT_SUCCESS;


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

In the example above, the const attribute tells the compiler that the return value of a function depends only on the input parameters and the function does not use global variables.


Question: How many programming languages are there as of April 2019?

C (programming language)

The softer analogue of the const attribute is the pure attribute, which allows the function to use global variables.


Question: How many programming languages are there as of April 2019?

C (programming language)


Question: How many programming languages are there as of April 2019?

C (programming language)

Development tools


Question: How many programming languages are there as of April 2019?

C (programming language)

C compilers


Question: How many programming languages are there as of April 2019?

C (programming language)

Some compilers come bundled with compilers for other programming languages (including C++) or are part of the software development environment.


Question: How many programming languages are there as of April 2019?

C (programming language)

BDS C


Question: How many programming languages are there as of April 2019?

C (programming language)

Borland C++


Question: How many programming languages are there as of April 2019?

C (programming language)

C++ Builder


Question: How many programming languages are there as of April 2019?

C (programming language)

Clang


Question: How many programming languages are there as of April 2019?

C (programming language)

Digital Mars


Question: How many programming languages are there as of April 2019?

C (programming language)

DJGPP


Question: How many programming languages are there as of April 2019?

C (programming language)

GNU Compiler Collection


Question: How many programming languages are there as of April 2019?

C (programming language)

Intel C++ compiler


Question: How many programming languages are there as of April 2019?

C (programming language)

LCC


Question: How many programming languages are there as of April 2019?

C (programming language)

Microsoft Visual Studio


Question: How many programming languages are there as of April 2019?

C (programming language)

MinGW


Question: How many programming languages are there as of April 2019?

C (programming language)

Open Watcom


Question: How many programming languages are there as of April 2019?

C (programming language)

Oracle Solaris Studio


Question: How many programming languages are there as of April 2019?

C (programming language)

Pelles C


Question: How many programming languages are there as of April 2019?

C (programming language)

Portable C Compiler


Question: How many programming languages are there as of April 2019?

C (programming language)

Tiny C Compiler


Question: How many programming languages are there as of April 2019?

C (programming language)

Topspeed JPI C


Question: How many programming languages are there as of April 2019?

C (programming language)

Compilers for dynamic languages and platforms


Question: How many programming languages are there as of April 2019?

C (programming language)

Sometimes, in order to transfer certain libraries, functions and tools written in C to a different environment, it is necessary to compile C code into a higher level language or into virtual machine code, designed for such a language.


Question: How many programming languages are there as of April 2019?

C (programming language)

The following projects are designed for this purpose:


Question: How many programming languages are there as of April 2019?

C (programming language)

Emscripten [37] is a compiler from LLVM bytecode (for example, derived from C++) to JavaScript.


Question: How many programming languages are there as of April 2019?

C (programming language)

(old name Alchemy) [38] is a C/C++ compiler to ActionScript Virtual Machine (AVM2).


Question: How many programming languages are there as of April 2019?

C (programming language)

Allows you to use C libraries in Flash and Adobe AIR applications.


Question: How many programming languages are there as of April 2019?

C (programming language)

Clue [39] is a compiler from ANSI C to Lua, JavaScript, Perl, Java, Common Lisp.


Question: How many programming languages are there as of April 2019?

C (programming language)

AMPC [40] is a compiler from C to a Java virtual machine.


Question: How many programming languages are there as of April 2019?

C (programming language)

Integrated development environments


Question: How many programming languages are there as of April 2019?

C (programming language)

Eclipse is a free integrated development environment that supports the C language of the C99 standard.


Question: How many programming languages are there as of April 2019?

C (programming language)

It has a modular architecture, which makes it possible to connect support for different programming languages and additional features.


Question: How many programming languages are there as of April 2019?

C (programming language)

A module for integration with Git is available, but there is no integration with CMake.


Question: How many programming languages are there as of April 2019?

C (programming language)

KDevelop is a free integrated development environment that supports some features of the C language from the C11 standard.


Question: How many programming languages are there as of April 2019?

C (programming language)

It allows you to manage projects that use different programming languages, including C++ and Python, supports the CMake build system.


Question: How many programming languages are there as of April 2019?

C (programming language)

Among the features, it is worth noting the built-in support for Git at the file level and customizable formatting of the source code for different languages.


Question: How many programming languages are there as of April 2019?

C (programming language)

Unit testing tools


Question: How many programming languages are there as of April 2019?

C (programming language)

Since the C language does not provide a means to write code safely, and many elements of the language contribute to errors, writing high-quality and fault-tolerant code can only be guaranteed by creating automated tests.


Question: How many programming languages are there as of April 2019?

C (programming language)

Various implementations of third-party unit testing libraries are available to facilitate this testing.


Question: How many programming languages are there as of April 2019?

C (programming language)

The Check library provides a framework for testing C code in the common XUnit style.


Question: How many programming languages are there as of April 2019?

C (programming language)

Among the features, we can mention running tests in individual processes via fork (), which allows you to recognize segmentation errors in tests, and also makes it possible to set the maximum time execution of individual tests.


Question: How many programming languages are there as of April 2019?

C (programming language)

The Google Test library also provides testing according to the principles of XUnit, but is designed to test C++ code, which allows it to be used for testing code in C as well.