Skip to content

Assignment Makes Pointer From Integer Without A Cast Malloc In C

One problem is the calls to and the fact that you've not declared by including .

By default, functions are assumed to return an in pre-C99 code — in C99 code, you're supposed to declare a function before using it.

You need to compile with more warning options. If you use GCC, I recommend:

This pretty much ensures that you don't have undeclared functions (such as ) used. Depending on the version of GCC you use, you may get more or less warnings enabled by default. In general, newer versions are fussier, though it isn't quite that simple.


The other problem appears to be that you have a source file (name not given in the question) containing type definitions and function definitions such as:

Within this file the types are known. In your main code, you have:

The type name must be known in this file, but it appears that your code does not include a declaration for .

For types and functions that are going to be used in multiple source files, there should be a header defining the types and declaring the functions. The header should be used in both the source file that defines the functions and in the source files that use the types and functions.

For example, the header might be :

The header guards are important; they avoid problems with redefining types (though C11 has more flexibility than either C99 or C89 in handling redefinitions of s). The use of before the function name is not strictly necessary, though I prefer to see it — if only for symmetry with the that must be present before any variables that are declared in the header (if there are any — global variables should be avoided whenever possible).

Then the implementation file might start:

There's a good reason for putting the header first; it ensures that the header can be used on its own (which is important).

The main code also includes , and because the function is declared in the header, you avoid the compiler warning.

Несмотря на интенсивное движение, воздух был наполнен сладким ароматом севильских апельсиновых деревьев. Спустились сумерки - самое романтическое время суток.

Он подумал о Сьюзан. Но тут же в голову пришли слова Стратмора: Найдите кольцо.