Casting The Return of Malloc (), Calloc () and Realloc () - C

According to the discussion of I cast the result of malloc?, in C it is not recommended or correct to cast Malloc () return. Does this also apply to Calloc() and Realloc () functions?
Taking advantage, the correct is to speak Cast, Casting or are both correct?

Author: Comunidade, 2018-12-31

2 answers

On the question of the words Cast and casting, the C specification uses the two words with different meanings.

A draft of the last specification can be found at the link below.

Http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

In this document, in section 6.5.4 paragraph 5, the following is established:

Preceding an expression by a parenthesized type name converts the value of the expression to the named type. This construction is called a cast. A cast that specifies no conversion has no effect on the type or value of an expression.

Already in Section 7.12.6.5, paragraph 2, it is said:

...they are equivalent to calling the corresponding logb function and casting the returned value to type int.

So I conclude that that type in parentheses that precedes an expression is called cast and what it is doing is casting.

In other words, Cast is that construction of the language and casting is what it does.

 3
Author: wldomiciano, 2020-08-21 15:31:51

Yes, functions have the same questions, not least because in essence they return the same thing, only what is done internally is that different.

I don't think language is our focus, but it always depends on the context to define which is the correct word, both can be used in the context of programming, each in a more specific context has a different grammatical meaning, but nothing that directly interferes with the concept of programming.

 5
Author: Maniero, 2019-01-03 10:14:33