

Makes Pointer From Integer Without a Cast: Fix It Now!

Our research team has ensured that this will be your best resource on these error messages, and you won’t have to read another article about it again. With that said, launch your code that’s showing the error messages, and let’s fix it for you.
– You Assigned an Integer to a Pointer
– you want to convert an integer to a pointer, – you passed a variable name to the “printf()” function, – you used “struct _io_file” in a wrong way, – you copied a string to an invalid location, – you’re setting a pointer to a different type, – use equal data types during assignment, – ensure the pointer and integer have the same sizes, – pass a “format string” to the “printf()” function, – use a function that returns a pointer to “struct _io_file”, – copy the string to character array or character pointer, – assign pointers of compatible types, why your code made a pointer from an integer without a cast.
Your code made a pointer from an integer without a cast because you assigned an integer to a pointer or you want to convert an integer to a pointer. Other causes include the passing of a variable name to the “printf()” function and using “struct _io_file in the wrong way.
Finally, the following are also possible causes:
- You copied a string to an invalid location
- You’re setting a pointer to a different type
If you assign an integer to a pointer, it will lead to the “ assignment makes pointer from integer without a cast c programming ” error. For example, in the following, the “num_array” variable is an unsigned integer type while “tmp_array” is a pointer.
Later, an error will occur when the “for” loop tries to copy the values of the “num_array” to the “tmp_array” pointer using a variable assignment.

For example, in the following, the “theta” variable is an integer while “ptr_theta” is a pointer. Both have different sizes, and you can’t convert the integer to a pointer.
If you pass a variable name to the “printf()” function, that’s when the compiler will throw the “ passing argument 1 of ‘printf’ makes pointer from integer without a cast ” error.
For example, in the following, “num_val” is an integer variable, and the code is trying to print it using the “printf()” function.
When you assign an integer to a pointer of “struct _io_file”, that’s when you’ll get the “ assignment to file aka struct _io_file from int makes pointer from integer without a cast ” error. For example, in the following code, “FILE” is a “typedef” for “struct _io_file”. This makes it a pointer to “struct _io_file”.
Later, the code assigned it to the integer “alpha,” and this will lead to an error stated below:

Now, in the following, the code is trying to copy a string (“source”) into an integer (“destination”), and this leads to an error because it’s not a valid operation:
When your code sets a pointer to a different type, your compiler will show the “ incompatible pointer type ” error. In the following code, “pacifier” is an integer pointer, while “qwerty” is a character pointer.
Both are incompatible, and your C compiler will not allow this or anything similar in your code.
How To Stop a Pointer Creation From an Integer Without a Cast
You can stop a pointer creation from an integer without a cast if you use equal data types during the assignment or ensure the integer and pointer have the same sizes. What’s more, you can pass a “format string” to “printf()” and use a function that returns a pointer to “struct _io_file”.
- Copy the string to a character array or character pointer
- Assign pointers of compatible types
During a variable assignment, use variables of equal data types. In our first example, we assigned a pointer (uint8_t *tmp_array) to an unsigned integer (uint8_t num_array) and it led to a compile-time error.
Now, the following is the revised code, and we’ve changed “tmp_array” to a real array. This will prevent the “ gcc warning: assignment makes pointer from integer without a cast ” error during compilation.

Now, the fix is to use “intptr_t” from the “stdint.h” header file because it guarantees that the pointer and integer will have the same sizes. We’ve used it in the following code, and you can compile it without an error.
To fix the “pointer to integer without a cast” in the “printf()” function, pass a “format string” as its first argument. How you write the “format string” depends on the variable that you’ll print. In the following updated code, “num_val” is an integer, so the “format string” is “%d”.
When you’re using “FILE” from the “stdlib.h” header file, you can prevent any “pointer from integer” error if you use a function that returns a pointer to “struct _io_file”.
An example of such a function is “fopen()” which allows you to open a file in C programming. Now, the following is a rewrite of the code that causes the pointer error in “struct _io_file”. This time, we use “fopen()” as a pointer to “FILE”.

Now, in the following code, we’ve changed “destination” from an integer to a “character array”. This means “strcpy()” can copy a string into this array without an error.
Meanwhile, the following is another version that turns the “destination” into a “character pointer”. With this, you’ll need to allocate memory using the “malloc()” function from the “stdlib.h” header file.
When you’re assigning pointers, ensure that they’re compatible by changing their data type . The following is the updated code for the “charlie” example , and “qwerty” is now an integer.
This article explained why your code made a pointer without a cast and how you can fix it. The following is a summary of what we talked about:
- An attempt to convert an integer to a pointer will lead to the “makes pointer from integer without a cast wint conversion” error.
- To prevent an “incompatible pointer type” error, don’t set a pointer to a different type.
- If you’re using the “printf()” function, and you want to prevent any “pointer to integer” error, always pass a “format specifier”.
At this stage, you’ll be confident that you can work with integers and pointers in C programming without an error. Save our article, and share it with your developer communities to help them get rid of this error as well.
- Recent Posts

- HTTP Error 500.19 – Internal Server Error: Fixing the Issue - September 7, 2023
- 400 Bad Request Nginx: A Comprehensive Fixing Guide - September 6, 2023
- Longer Object Length Is Not a Multiple of Shorter Object Length - September 5, 2023
Leave a Comment Cancel reply
Save my name, email, and website in this browser for the next time I comment.
Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов

Как дословно переводится assignment makes pointer from integer without a cast?
- Вопрос задан более трёх лет назад
- 1655 просмотров
Войдите, чтобы написать ответ
Нужно ли писать суффиксы литералов.
- 2 подписчика
- 160 просмотров

Где найти такую CLI?
- 1 подписчик
- 180 просмотров
Где ошибка в коде?
- 99 просмотров
Использует ли кто-то аннотации sal?
- 5 подписчиков
- 275 просмотров
Можно ли запустить программу на языке C в операционной системе FreeDOS или MSDOS?
- 303 просмотра

Как сделать побитовое умножение и сложение большого числа decimal?
- 217 просмотров
Почему программа «Конвентер Валют» выдаёт 0.000000 при любом значении?
- 100 просмотров
Как присвоить динамическому массиву типа void* значение в Си?
- 135 просмотров
Как правильно структурировать проект C?
- 164 просмотра


Как скомпилировать код C в .ko?
- 188 просмотров
- Показать ещё Загружается…
Минуточку внимания
Войдите на сайт.
- unixforum.org
Форум для пользователей UNIX-подобных систем
- Статус форума
- unixforum.org Погружение Программирование Программирование для начинающих
Приведение int к указателю в С
Модератор: Модераторы разделов

Сообщение anjolio » 09.01.2009 13:12
Код: Выделить всё

Re: Приведение int к указателю в С
Сообщение serzh-z » 09.01.2009 13:47
anjolio писал(а): ↑ 09.01.2009 13:12 Так вот, внимание вопрос! Как привести int к указателю?
Сообщение anjolio » 09.01.2009 14:01
serzh-z писал(а): ↑ 09.01.2009 13:47 Нельзя возвращать из функции указатель на стековую переменную name.

Сообщение gluk47 » 09.01.2009 14:19

Сообщение whirlwind » 09.01.2009 14:26
anjolio писал(а): ↑ 09.01.2009 13:12 Код: Выделить всё anjolio@desktop:~/Разработка/renamer$ gcc main.c main.c: In function ‘main’: main.c:8: warning: assignment makes pointer from integer without a cast
Сообщение serzh-z » 09.01.2009 14:28
Сообщение gluk47 » 09.01.2009 14:34
Сообщение anjolio » 09.01.2009 14:36
Сообщение serzh-z » 09.01.2009 14:47
anjolio писал(а): ↑ 09.01.2009 14:36 Это и есть борьба с утечками памяти? smile.gif
Сообщение anjolio » 09.01.2009 14:50

Сообщение AestheteAnimus » 09.01.2009 15:36
Сообщение anjolio » 09.01.2009 15:45
Сообщение serzh-z » 09.01.2009 15:46
Сообщение AestheteAnimus » 09.01.2009 16:00
anjolio писал(а): ↑ 09.01.2009 15:45 AestheteAnimus , огромное спасибо! Всё понятно и по полочкам!
serzh-z писал(а): ↑ 09.01.2009 15:46 Код: Выделить всё char p[100]; if (get_name_addition(p)) { }
Вернуться в «Программирование для начинающих»
- Часовой пояс: UTC+03:00
- Связаться с администрацией
Enabled by default warnings
The GNU Compiler Collection (GCC) 4.6.3 might generate enabled by default warnings that cannot be suppressed. To compile without the warnings, fix your code.
Enabled by default warnings for NULL
Problem: I received the following warning: return makes pointer from integer without a cast [enabled by default]
Solution: Investigate and fix code that generates this warning.
Problem: I received the following warning: assignment makes pointer from integer without a cast [enabled by default]
Solution: Identify and change coding errors such as casting the rvalue to an unsigned int when the lvalue is a pointer. This coding error might not be obvious in complex code; for example, when the code is in a segment that uses a C macro embedded in another C macro.
Problem: I received the following warning: comparison between pointer and integer [enabled by default]
Solution: Identify and change coding errors such as casting the rvalue to an unsigned int when the lvalue is a pointer.
Enabled by default warning for initialized extern variables
Problem: I received the following warning: 'REGISTER_NAMES' initialized and declared 'extern' [enabled by default]
Investigate and fix any code that has extern variables that are initialized, by removing the initialization or by removing the extern storage class specifier.
Enabled by default warning for undeclared extern variables
Problem: I received the following warning: type 'CMOA()::itcpc' with no linkage used to declare variable 'CMOA()::itcpc* itcpc_ptr' with linkage [enabled by default]

- C and C++ FAQ
- Mark Forums Read
- View Forum Leaders
- What's New?
- Get Started with C or C++
- C++ Tutorial
- Get the C++ Book
- All Tutorials
- Advanced Search

- General Programming Boards
- C Programming
Assignment makes pointer from integer without a cast
- Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems
Thread: Assignment makes pointer from integer without a cast
Thread tools.
- Show Printable Version
- Email this Page…
- Subscribe to this Thread…
- View Profile
- View Forum Posts

I keep getting this error message: "warning: assignment makes pointer from integer without a cast" for line 17 (which I've made red). I've gotten this message a few times before, but I can't remember how I fixed it, and I can't figure out how to fix this one. Any suggestions? Also, it's a code that will take a password entered by the user and then run several for loops until it matches the password. It prints what it's figured out each time it guesses a new letter. Code: #include <stdio.h> #include <string.h> int main(void) { int i, j; char password[25]; char cracked[25]; char *p; char guess = '!'; printf("Enter a password of 25 characters or less: \n"); scanf("%s", password); printf("Password is being cracked..."); for (i = 0, p = password[i]; i < 25; i++, p++) { for(j = 0; j < 90; j++) { if (*p == guess) { strcpy(p, cracked); printf("\t %s \n"); break; } guess++; } //end <search> for loop } //end original for loop return 0; }
Last edited by deciel; 12-13-2011 at 01:57 AM .

Code: for (i = 0, p = password[i]; i < 25; i++, p++) password[i] is the value at index i of password . You want the address of said value, so you want p = &password[i] (or, equivalently, p = password + i ).
Oh! Thank you, it worked!

Originally Posted by deciel I keep getting this error message: "warning: for (i = 0, p = password[i]; i < 25; i++, p++) [/CODE] Note: password[i] == password[0] == *password since this is the assignment portion of for loop and i is set to zero (0).

If you want to set a pointer to the beginning of an array, just use Code: p = password An array name is essentially a pointer to the start of the array memory. Note, for a null terminated string, you could just test for Code: *p //or more explicitly *p == '\0' Also, a 25-element char array doesn't have room for a 25 character string AND a null terminator. And, ask yourself, what's going on when I enter, say a 10 character password, and i > 10.
- Private Messages
- Subscriptions
- Who's Online
- Search Forums
- Forums Home
- C++ Programming
- C# Programming
- Game Programming
- Networking/Device Communication
- Programming Book and Product Reviews
- Windows Programming
- Linux Programming
- General AI Programming
- Article Discussions
- General Discussions
- A Brief History of Cprogramming.com
- Contests Board
- Projects and Job Recruitment

- How to create a shared library on Linux with GCC - December 30, 2011
- Enum classes and nullptr in C++11 - November 27, 2011
- Learn about The Hash Table - November 20, 2011
- Rvalue References and Move Semantics in C++11 - November 13, 2011
- C and C++ for Java Programmers - November 5, 2011
- A Gentle Introduction to C++ IO Streams - October 10, 2011
Similar Threads
Assignment makes pointer from integer without a cast, warning: assignment makes integer from pointer without a cast, warning: assignment makes integer from pointer without a cast, ' assignment makes pointer from integer without a cast ".
- C and C++ Programming at Cprogramming.com
- Web Hosting
- Privacy Statement
Warning: assignment makes pointer from integer without a cast
c++ pointers struct
I'm doing cast from a pointer then it keeps me runing this warning (assignment makes pointer from integer without a cast). here's the code:
on main I call:
it runs a invallid free (strange, because if Raiz is NULL the free shouldn't had run. Can anyone help me with that problem, please? I think that this warning is the problem that keeps me from "freeing" too.
EDIT: OK problem about waring solved. But if I do the free 2 times it runs a invalid free (I have a function that does a free somethings, other-times not. If I do the free the "if(Raiz!=NULL)" should block the other free from runing. but it isn't.
Best Solution
One problem is the calls to malloc() and the fact that you've not declared malloc() by including <stdlib.h> .
By default, functions are assumed to return an int 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 malloc() ) 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 TipoApontador must be known in this file, but it appears that your code does not include a declaration for NovaSubArvore() .
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 tipopagina.h :
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 typedef s). The use of extern before the function name is not strictly necessary, though I prefer to see it — if only for symmetry with the extern 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 tipopagina.c might start:
There's a good reason for putting the tipopagina.h header first; it ensures that the header can be used on its own (which is important).
The main code also includes tipopagina.h , and because the function NovaSubArvore() is declared in the header, you avoid the compiler warning.
Related Solutions
Assignment makes pointer from integer without cast.
C strings are not anything like Java strings. They're essentially arrays of characters.
You are getting the error because strToLower returns a char. A char is a form of integer in C. You are assigning it into a char[] which is a pointer. Hence "converting integer to pointer".
Your strToLower makes all its changes in place, there is no reason for it to return anything, especially not a char. You should "return" void, or a char*.
On the call to strToLower, there is also no need for assignment, you are essentially just passing the memory address for cString1.
In my experience, Strings in C are the hardest part to learn for anyone coming from Java/C# background back to C. People can get along with memory allocation (since even in Java you often allocate arrays). If your eventual goal is C++ and not C, you may prefer to focus less on C strings, make sure you understand the basics, and just use the C++ string from STL.
- Warning: assignment makes integer from pointer without a cast
When you write the statement
the compiler sees the constant string "abcdefghijklmnop" like an array. Imagine you had written the following code instead:
Now, it's a bit clearer what is going on. The left-hand side, *src , refers to a char (since src is of type pointer-to- char ) whereas the right-hand side, otherstring , refers to a pointer.
This isn't strictly forbidden because you may want to store the address that a pointer points to. However, an explicit cast is normally used in that case (which isn't too common of a case). The compiler is throwing up a red flag because your code is likely not doing what you think it is.
It appears to me that you are trying to assign a string. Strings in C aren't data types like they are in C++ and are instead implemented with char arrays. You can't directly assign values to a string like you are trying to do. Instead, you need to use functions like strncpy and friends from <string.h> and use char arrays instead of char pointers. If you merely want the pointer to point to a different static string, then drop the * .
Related Question

IMAGES
VIDEO
COMMENTS
... it looks correct), this kind of warning happens when the definition is after the first use of the function, and there is no prototype.
При отладки получаю предупреждение 'Type assignment makes pointer from integer without a cast' На вот такой код:
You can stop a pointer creation from an integer without a cast if you use equal data types during the assignment or ensure the integer and pointer have the same
Или initialization makes pointer from integer without a cast ? Почему from? Почему makes, а не does или uses, например? Почему не assignment
anjolio@desktop:~/Разработка/renamer$ gcc main.c main.c: In function 'main': main.c:8: warning: assignment makes pointer from integer without a cast.
Problem: I received the following warning: assignment makes pointer from integer without a cast [enabled by default]. Solution: Identify and change coding
I keep getting this error message: "warning: assignment makes pointer from integer without a cast" for line 17 (which I've made red).
Ошибка assignment makes pointer from integer without a cast [enabled by default] C (СИ) Решение и ответ на вопрос 1347309.
It means you are using the wrong language. · And casts are also really primitive and should not be in languages, often they are just to get around programmer
This pretty much ensures that you don't have undeclared functions (such as malloc() ) used. Depending on the version of GCC you use, you may get more or less
assignment makes integer from pointer without a cast c/c++ warning explained #syntax #c/c++ #compiler #error #warning.