Do (Cast) the return of Malloc (), Calloc () and Realloc () - C

4

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

    
asked by anonymous 31.12.2018 / 14:57

2 answers

5

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

I do not 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 programming context, each in a more specific context has a different grammatical meaning, but nothing that interferes directly into the programming concept.

    
31.12.2018 / 15:22
3

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

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

link

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.

In section 7.12.6.5, paragraph 2, it is said:

  

...

...

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

In other words, cast is this language construction and casting is what it does.

    
01.01.2019 / 08:12