Converting Pointers to Integers: Avoiding Cast Errors & Mastering the Process

David Henegar

In this guide, we will cover how to convert pointers to integers and vice versa without running into any cast errors. We will also walk you through the step-by-step process of mastering pointer and integer conversions in C/C++.

Table of Contents

  • Why Convert Pointers to Integers
  • Understanding uintptr_t
  • Step-by-Step Guide
  • Converting Pointers to Integers
  • Converting Integers to Pointers

Why Convert Pointers to Integers? {#why-convert-pointers-to-integers}

There are several use cases where you might need to convert pointers to integers and vice versa. Some common reasons include:

  • Manipulating memory addresses for low-level programming.
  • Serializing and deserializing data.
  • Storing pointers in a generic data structure.
  • Debugging and logging purposes.

However, when converting pointers to integers, it is crucial to avoid any errors that may arise from incorrect casting.

Understanding uintptr_t {#understanding-uintptr_t}

To safely convert pointers to integers, it is essential to use the uintptr_t data type. This is an unsigned integer type that is large enough to store the value of a pointer. It is available in the <stdint.h> header in C and the <cstdint> header in C++.

Using uintptr_t , you can safely cast a pointer to an integer and back to a pointer without losing any information. This ensures that the process is safe, fast, and efficient.

Step-by-Step Guide {#step-by-step-guide}

Converting pointers to integers {#converting-pointers-to-integers}.

To convert a pointer to an integer, follow these steps:

  • Include the <stdint.h> header (C) or the <cstdint> header (C++) in your program.
  • Cast your pointer to uintptr_t .

Converting Integers to Pointers {#converting-integers-to-pointers}

To convert an integer to a pointer, follow these steps:

  • Cast your integer to the required pointer type using a double cast.

FAQs {#faqs}

Why can't i just use a regular int or unsigned int to store pointers {#regular-int}.

While it may work on some platforms where the size of an int is equal to the size of a pointer, it is not guaranteed to be portable across different systems. Using uintptr_t ensures your code remains portable and safe.

Are there performance implications when using uintptr_t ? {#performance}

The performance impact of using uintptr_t is minimal. Most modern compilers can optimize the casting operations, resulting in little to no overhead.

When should I use intptr_t instead of uintptr_t ? {#intptr_t}

intptr_t is a signed integer type that can hold a pointer value. It is useful when you need to perform arithmetic operations on pointers that may result in negative values. However, in most cases, uintptr_t is recommended.

Is it safe to perform arithmetic operations on integers representing pointers? {#pointer-arithmetic}

Performing arithmetic operations on integers representing pointers can lead to undefined behavior if the resulting integer doesn't correspond to a valid memory address. It is generally safer to perform arithmetic operations on pointers directly.

How do I avoid losing information when casting pointers to integers? {#avoid-losing-information}

By using uintptr_t , you ensure that the integer is large enough to store the value of a pointer without losing any information. Make sure always to use uintptr_t when converting pointers to integers.

Related Links

  • C++ Reference: uintptr_t
  • C Reference: uintptr_t
  • Understanding Pointers in C and C++

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Lxadm.com.

Your link has expired.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.

DEV Community

DEV Community

Coder Legion

Posted on Oct 4, 2023 • Originally published at coderlegion.com

Assignment makes integer from pointer without a cast in c

Programming can be both rewarding and challenging. You work hard on your code, and just when it seems to be functioning perfectly, an error message pops up on your screen, leaving you frustrated and clueless about what went wrong. One common error that programmers encounter is the "Assignment makes integer from pointer without a cast" error in C.

This error occurs when you try to assign a value from a pointer variable to an integer variable without properly casting it. To fix this error, you need to make sure that you cast the pointer value to the appropriate data type before assigning it to an integer variable. In this article, we will dive deeper into the causes of this error and provide you with solutions to overcome it.

Image description

What makes this error occur?

I will present some cases that triggers that error to occur, and they are all have the same concept, so if you understanded why the failure happens, then you will figure out how to solve all the cases easily.

Case 1: Assignment of a pointer to an integer variable

In this simple code we have three variables, an integer pointer "ptr", and two integers "n1" and "n2". We assign 2 to "n1", so far so good, then we assign the address of "n2" to "ptr" which is the suitable storing data type for a pointer, so no problems untill now, till we get to this line "n2 = ptr" when we try to assign "ptr" which is a memory address to "n2" that needs to store an integer data type because it's not a pointer.

Case 2: Returning a Pointer from a Function that Should Return an Integer

As you can see, it's another situation but it's the same idea which causes the compilation error. We are trying here to assign the return of getinteger function which is a pointer that conatains a memory address to the result variable that is an int type which needs an integer

Case 3: Misusing Array Names as Pointers

As we might already know, that the identifier (name) of the array is actually a pointer to the array first element memory address, so it's a pointer after all, and assigning a pointer type to int type causes the same compilation error.

The solutions

The key to avoiding the error is understanding that pointers and integers are different types of variables in C. Pointers hold memory addresses, while integers hold numeric values. We can use either casting, dereferencing the pointer or just redesign another solution for the problem we are working on that allows the two types to be the same. It all depending on the situation.

Let's try to solve the above cases:

Case 1: Solution: Deferencing the pointer

We need in this case to asssign an int type to "n2" not a pointer or memory address, so how do we get the value of the variable that the pointer "ptr" pointing to? We get it by deferencing the pointer, so the code after the fix will be like the following:

Case 2: Solution: Choosing the right data type

In this case we have two options, either we change the getinteger returning type to int or change the result variable type to a pointer. I will go with the latter option, because there are a lot of functions in the C standard library that returning a pointer, so what we can control is our variable that takes the function return. So the code after the fix will be like the following:

We here changed the result variable from normal int to an int pointer by adding "*".

Case 3: Solution: Using the array subscript operator

In this case we can get the value of any number in the array by using the subscript opeartor ([]) on the array with the index number like: myarray[1] for the second element which is 2. If we still remember that the array identifier is a pointer to the array first memory, then we can also get the value of the array first element by deferencing the array identifier like: *myarray which will get us 1.

But let's solve the case by using the subscript opeartor which is the more obvious way. So the code will be like the following:

Now the number 1 is assigned to myint without any compilation erros.

The conclusion

In conclusion, the error "assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast" arises in C programming when there is an attempt to assign a memory address (held by a pointer) directly to an integer variable. This is a type mismatch as pointers and integers are fundamentally different types of variables in C.

To avoid or correct this error, programmers need to ensure they are handling pointers and integers appropriately. If the intent is to assign the value pointed by a pointer to an integer, dereferencing should be used. If a function is meant to return an integer, it should not return a pointer. When dealing with arrays, remember that the array name behaves like a pointer to the first element, not an individual element of the array.

Top comments (0)

pic

Templates let you quickly answer FAQs or store snippets for re-use.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink .

Hide child comments as well

For further actions, you may consider blocking this person and/or reporting abuse

zmsoft profile image

The Dark Side of App Development that Individual Developers Absolutely Need to Know ~ Don't Lose to Fraud ~

zmsoft - Apr 13

epakconsultant profile image

Fulfillment Centers for Drop Shipping

sajjad hussain - Apr 13

web3space profile image

Shopify Store Integration with Online Marketplaces

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Ubuntu Forums

  • Unanswered Posts
  • View Forum Leaders
  • Contact an Admin
  • Forum Council
  • Forum Governance
  • Forum Staff

Ubuntu Forums Code of Conduct

  • Forum IRC Channel
  • Get Kubuntu
  • Get Xubuntu
  • Get Lubuntu
  • Get Ubuntu Studio
  • Get Mythbuntu
  • Get Edubuntu
  • Get Ubuntu GNOME
  • Get Ubuntu Kylin
  • Get Ubuntu Budgie
  • Get Ubuntu Mate
  • Ubuntu Code of Conduct
  • Ubuntu Wiki
  • Community Wiki
  • Launchpad Answers
  • Ubuntu IRC Support
  • Official Documentation
  • User Documentation
  • Distrowatch
  • Bugs: Ubuntu
  • PPAs: Ubuntu
  • Web Upd8: Ubuntu
  • OMG! Ubuntu
  • Ubuntu Insights
  • Planet Ubuntu
  • Full Circle Magazine
  • Activity Page
  • Please read before SSO login
  • Advanced Search

Home

  • The Ubuntu Forum Community
  • Ubuntu Specialised Support
  • Development & Programming
  • Programming Talk

[SOLVED] C - assigment makes integer from pointer without a cast warning

Thread: [solved] c - assigment makes integer from pointer without a cast warning, thread tools.

  • Show Printable Version
  • Subscribe to this Thread…
  • View Profile
  • View Forum Posts
  • Private Message

usernamer is offline

I know it's a common error, and I've tried googling it, looked at a bunch of answers, but I still don't really get what to do in this situation.... Here's the relevant code: Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main( int argc, char *argv[] ) { char path[51]; const char* home = getenv( "HOME" ); strcpy( path, argv[1] ); path[1] = home; return 0; } -- there is more code in the blank lines, but the issue's not there (I'm fairly sure), so didn't see the point in writing out 100 odd lines of code. I've tried some stuff like trying to make a pointer to path[1], and make that = home, but haven't managed to make that work (although maybe that's just me doing it wrong as opposed to wrong idea?) Thanks in advance for any help

r-senior is offline

Re: C - assigment makes integer from pointer without a cast warning

path[1] is the second element of a char array, so it's a char. home is a char *, i.e. a pointer to a char. You get the warning because you try to assign a char* to a char. Note also the potential to overflow your buffer if the content of the argv[1] argument is very long. It's usually better to use strncpy.
Last edited by r-senior; March 10th, 2013 at 03:03 PM . Reason: argv[1] would overflow, not HOME. Corrected to avoid confusion.
Please create new threads for new questions. Please wrap code in code tags using the '#' button or enter it in your post like this: [code]...[/code].
  • Visit Homepage

Christmas is offline

You can try something like this: Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main( int argc, char *argv[] ) { char *path; const char *home = getenv("HOME"); path = malloc(strlen(home) + 1); if (!path) { printf("Error\n"); return 0; } strcpy(path, home); printf("path = %s\n", path); // if you want to have argv[1] concatenated with path if (argc >= 2) { path = malloc(strlen(home) + strlen(argv[1]) + 1); strcpy(path, argv[1]); strcat(path, home); printf("%s\n", path); } // if you want an array of strings, each containing path, argv[1]... char **array; int i; array = malloc(argc * sizeof(char*)); array[0] = malloc(strlen(home) + 1); strcpy(array[0], home); printf("array[0] = %s\n", array[0]); for (i = 1; i < argc; i++) { array[i] = malloc(strlen(argv[i]) + 1); strcpy(array[i], argv[i]); printf("array[%d] = %s\n", i, array[i]); } // now array[i] will hold path and all the argv strings return 0; } Just as above, your path[51] is a string while path[1] is only a character, so you can't use strcpy for that.
Last edited by Christmas; March 10th, 2013 at 09:51 PM .
TuxArena - Ubuntu/Debian/Mint Tutorials | Linux Stuff Intro Tutorials | UbuTricks I play Wesnoth sometimes. And AssaultCube .
Originally Posted by Christmas You can try something like this: Code: #include <stdio.h> #include <stdlib.h> #include <string.h> int main( int argc, char *argv[] ) { char *path; const char *home = getenv("HOME"); path = malloc(strlen(home) + 1); if (!path) { printf("Error\n"); return 0; } strcpy(path, home); printf("path = %s\n", path); // if you want to have argv[1] concatenated with path if (argc >= 2) { path = malloc(strlen(home) + strlen(argv[1]) + 1); strcpy(path, argv[1]); strcat(path, home); printf("%s\n", path); } // if you want an array of strings, each containing path, argv[1]... char **array; int i; array = malloc(argc * sizeof(char*)); array[0] = malloc(strlen(home) + 1); strcpy(array[0], home); printf("array[0] = %s\n", array[0]); for (i = 1; i < argc; i++) { array[i] = malloc(strlen(argv[i]) + 1); strcpy(array[i], argv[i]); printf("array[%d] = %s\n", i, array[i]); } // now array[i] will hold path and all the argv strings return 0; } Just as above, your path[51] is a string while path[1] is only a character, so you can't use strcpy for that. Excellent point. I've basically fixed my problem by reading up on pointers again (haven't done any C for a little while, so forgot some stuff), and doing: Code: path[1] = *home; the code doesn't moan at me when I compile it, and it runs okay (for paths which aren't close to 51 at least), but after reading what you read, I just wrote a quick program and found out that getenv("HOME") is 10 characters long, not 1 like I seem to have assumed, so I'll modify my code to fix that.
Yes, getenv will return the path to your home dir, for example /home/user, but path[1] = *home will still assign the first character of home to path[1] (which would be '/').
  • Private Messages
  • Subscriptions
  • Who's Online
  • Search Forums
  • Forums Home
  • New to Ubuntu
  • General Help
  • Installation & Upgrades
  • Desktop Environments
  • Networking & Wireless
  • Multimedia Software
  • Ubuntu Development Version
  • Virtualisation
  • Server Platforms
  • Ubuntu Cloud and Juju
  • Packaging and Compiling Programs
  • Development CD/DVD Image Testing
  • Ubuntu Application Development
  • Ubuntu Dev Link Forum
  • Bug Reports / Support
  • System76 Support
  • Apple Hardware Users
  • Recurring Discussions
  • Mobile Technology Discussions (CLOSED)
  • Announcements & News
  • Weekly Newsletter
  • Membership Applications
  • The Fridge Discussions
  • Forum Council Agenda
  • Request a LoCo forum
  • Resolution Centre
  • Ubuntu/Debian BASED
  • Arch and derivatives
  • Fedora/RedHat and derivatives
  • Mandriva/Mageia
  • Slackware and derivatives
  • openSUSE and SUSE Linux Enterprise
  • Gentoo and derivatives
  • Any Other OS
  • Assistive Technology & Accessibility
  • Art & Design
  • Education & Science
  • Documentation and Community Wiki Discussions
  • Outdated Tutorials & Tips
  • Ubuntu Women
  • Arizona Team - US
  • Arkansas Team - US
  • Brazil Team
  • California Team - US
  • Canada Team
  • Centroamerica Team
  • Instalación y Actualización
  • Colombia Team - Colombia
  • Georgia Team - US
  • Illinois Team
  • Indiana - US
  • Kentucky Team - US
  • Maine Team - US
  • Minnesota Team - US
  • Mississippi Team - US
  • Nebraska Team - US
  • New Mexico Team - US
  • New York - US
  • North Carolina Team - US
  • Ohio Team - US
  • Oklahoma Team - US
  • Oregon Team - US
  • Pennsylvania Team - US
  • Texas Team - US
  • Uruguay Team
  • Utah Team - US
  • Virginia Team - US
  • West Virginia Team - US
  • Australia Team
  • Bangladesh Team
  • Hong Kong Team
  • Myanmar Team
  • Philippine Team
  • Singapore Team
  • Albania Team
  • Catalan Team
  • Portugal Team
  • Georgia Team
  • Ireland Team - Ireland
  • Kenyan Team - Kenya
  • Kurdish Team - Kurdistan
  • Lebanon Team
  • Morocco Team
  • Saudi Arabia Team
  • Tunisia Team
  • Other Forums & Teams
  • Afghanistan Team
  • Alabama Team - US
  • Alaska Team - US
  • Algerian Team
  • Andhra Pradesh Team - India
  • Austria Team
  • Bangalore Team
  • Bolivia Team
  • Cameroon Team
  • Colorado Team - US
  • Connecticut Team
  • Costa Rica Team
  • Ecuador Team
  • El Salvador Team
  • Florida Team - US
  • Galician LoCo Team
  • Hawaii Team - US
  • Honduras Team
  • Idaho Team - US
  • Iowa Team - US
  • Jordan Team
  • Kansas Team - US
  • Louisiana Team - US
  • Maryland Team - US
  • Massachusetts Team
  • Michigan Team - US
  • Missouri Team - US
  • Montana Team - US
  • Namibia Team
  • Nevada Team - US
  • New Hampshire Team - US
  • New Jersey Team - US
  • Northeastern Team - US
  • Panama Team
  • Paraguay Team
  • Quebec Team
  • Rhode Island Team - US
  • Senegal Team
  • South Carolina Team - US
  • South Dakota Team - US
  • Switzerland Team
  • Tamil Team - India
  • Tennessee Team - US
  • Trinidad & Tobago Team
  • Uganda Team
  • United Kingdom Team
  • US LoCo Teams
  • Venezuela Team
  • Washington DC Team - US
  • Washington State Team - US
  • Wisconsin Team
  • Za Team - South Africa
  • Zimbabwe Team

Tags for this Thread

View Tag Cloud

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is Off
  • HTML code is Off
  • Ubuntu Forums

What is Assignment Makes Pointer From Integer Without A Cast and How Can It Be Avoided?

Understanding the pointer-integer conundrum in programming.

In the realm of programming, particularly in languages like C and C++, pointers play a crucial role in managing memory and optimizing the performance of applications. However, they can also be a source of confusion and errors, especially for those new to these languages. One common error that programmers encounter is the “assignment makes pointer from integer without a cast” warning or error. This message can be perplexing, but understanding its meaning is essential for writing clean, efficient, and error-free code.

Decoding the Warning: Assignment Makes Pointer from Integer Without a Cast

The warning “assignment makes pointer from integer without a cast” is a compiler message that indicates a potential issue in your code. It occurs when an integer value is assigned to a pointer variable without explicitly casting the integer to a pointer type. This can happen for various reasons, such as mistakenly using an integer as a memory address or overlooking the need for a type conversion.

Why Does This Warning Matter?

Ignoring this warning can lead to undefined behavior in your program. Since pointers and integers are fundamentally different types, treating an integer as a memory address can cause your program to access memory locations it shouldn’t, leading to crashes, data corruption, or security vulnerabilities.

Examples of Pointer-Integer Assignment Issues

To better understand the warning, let’s look at some examples where this issue might arise:

In the example above, the variable num is an integer, and ptr is a pointer to an integer. The assignment of num to ptr without a cast triggers the warning.

Root Causes of the Pointer-Integer Assignment Warning

Several scenarios can lead to this warning. Understanding these scenarios can help you avoid the issue in your code.

  • Accidental assignment of an integer to a pointer variable.
  • Using an integer as a function return value where a pointer is expected.
  • Incorrectly using an integer constant as a null pointer.
  • Forgetting to allocate memory before assigning it to a pointer.

Strategies to Avoid Pointer-Integer Assignment Issues

To prevent the “assignment makes pointer from integer without a cast” warning, you can employ several strategies:

  • Always use explicit casting when converting an integer to a pointer.
  • Ensure that functions returning pointers do not accidentally return integers.
  • Use the NULL macro or nullptr (in C++) for null pointers instead of integer constants.
  • Properly allocate memory using functions like malloc or new before assigning it to pointers.

Using Explicit Casting

Explicit casting involves converting one data type to another by specifying the target type. In the context of pointers and integers, you can use a cast to tell the compiler that you intentionally want to treat an integer as a pointer.

Proper Function Return Types

When writing functions that are supposed to return pointers, ensure that the return type is correctly declared as a pointer type, and that the return statements within the function adhere to this type.

Using NULL or nullptr

Instead of using integer constants like 0 for null pointers, use the NULL macro in C or nullptr in C++ to avoid confusion and potential warnings.

Memory Allocation

Before assigning a pointer, ensure that it points to a valid memory location by using memory allocation functions.

Advanced Considerations and Best Practices

Beyond the basic strategies, there are advanced considerations and best practices that can help you write robust pointer-related code:

  • Use static analysis tools to catch potential pointer-related issues before runtime.
  • Adopt coding standards that discourage unsafe practices with pointers and integers.
  • Understand the underlying architecture and how pointers are represented and used.
  • Regularly review and refactor code to improve clarity and safety regarding pointer usage.

FAQ Section

What is a pointer in programming.

A pointer is a variable that stores the memory address of another variable. Pointers are used for various purposes, such as dynamic memory allocation, implementing data structures like linked lists, and optimizing program performance.

Why is casting necessary when assigning an integer to a pointer?

Casting is necessary because pointers and integers are different data types with different interpretations. A cast explicitly informs the compiler that the programmer intends to treat the integer as a pointer, which can prevent unintended behavior.

Can ignoring the pointer-integer assignment warning lead to security issues?

Yes, ignoring this warning can lead to security issues such as buffer overflows, which can be exploited by attackers to execute arbitrary code or cause a program to crash.

Is it always safe to cast an integer to a pointer?

No, it is not always safe. The integer should represent a valid memory address that the program is allowed to access. Arbitrary casting without ensuring this can lead to undefined behavior and program crashes.

What is the difference between NULL and nullptr?

NULL is a macro that represents a null pointer in C and is typically defined as 0 or ((void *)0). nullptr is a keyword introduced in C++11 that represents a null pointer and is type-safe, meaning it cannot be confused with integer types.

The “assignment makes pointer from integer without a cast” warning is a signal from the compiler that there’s a potential issue in your code. By understanding what causes this warning and how to avoid it, you can write safer and more reliable programs. Always be mindful of the types you’re working with, use explicit casting when necessary, and follow best practices for pointer usage. With these strategies in place, you’ll be well-equipped to handle pointers and integers in your coding endeavors.

For further reading and a deeper understanding of pointers, integer casting, and related topics, consider exploring the following resources:

  • C Programming Language (2nd Edition) by Brian W. Kernighan and Dennis M. Ritchie
  • Effective Modern C++ by Scott Meyers
  • C++ Primer (5th Edition) by Stanley B. Lippman, Josée Lajoie, and Barbara E. Moo
  • ISO/IEC 9899:201x – International Standard for Programming Language C
  • ISO/IEC 14882:2017 – International Standard for Programming Language C++

These references provide a solid foundation for understanding the intricacies of pointers and type casting, as well as best practices for writing secure and efficient code in C and C++.

admin

  • Previous Your Network Preference Prevent Content From Loading
  • Next The Supplied Icloud Was Unable To Unlock This Volume

How Do I Lock My Icons On My Desktop Windows 10?

How Do I Lock My Icons On My Desktop Windows 10?

How to Take a Screenshot on a Toshiba Windows 10

How to Take a Screenshot on a Toshiba Windows 10

Is It Safe To Send Documents Via Email

Is It Safe To Send Documents Via Email

Your email address will not be published. Required fields are marked *

  • About JOE TECH
  • Privacy Policy

C Board

  • 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

Home

  • 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

deciel is offline

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 .

JohnGraham is offline

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!

sparkomemphis is offline

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).

Tclausex is offline

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

subscribe to a feed

  • 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

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

can't install cpan module Image::Magick

This question still has no solution (scroll down to "edit 5" to see the actual status).

I am trying to install Image::Magick on my headless Ubuntu server Ubuntu 14.04.2 LTS

Obviously the install-script is trying to include the header-file magick/MagickCore.h but can't find it.

When I search in search engines for magick/MagickCore.h then I find lots of postings where some people have the same problem and ask for, but instead of solution i did only find lots of answers saying "I have the same problem" - no solution.

Does anyone of you have a solution that works on a Ubuntu Server 14.04.2 ?

Edit 1: I already installed the package ImageMagic:

But I still get the error posted above.

Edit 2: Following the advise from one of the answers I also tried

followed by

And I still get the same error (script can't find magick/MagickCore.h)

Edit 3: I followed another advise and searched for magick/MagickCore.h . the answer was:

So I installed libmagickcore-dev (I exected sudo -i before):

This installation was successful, the previously missing header-file is now in the file system:

So I again tried

But I still get this error:

(» Datei oder Verzeichnis nicht gefunden « is German, my native language, and means » no such file or directory «)

Edit 4: Someone told me that the compiler is looking for magick/MagickCore.h not in /usr/include/ImageMagick/ but in /usr/include/ImageMagick-6/ . So I created a symbolic link:

and tried again to install the module:

So, the script did find magick/MagickCore.h , but now throws lots of other errors.

EDIT 5 (2015-09-17)

I've got the hint to install

apt-get install perlmagick

But it said, that the newest version already is installed. But I tried to install Image::Magick anyway. It still doesn't work:

This is the first error reported:

tmp-18091 for tmp-18091: Datei oder Verzeichnis nicht gefunden at /usr/share/perl/5.18/CPAN/Distribution.pm line 468.

which probably is in english:

tmp-18091 for tmp-18091: no such file or directory at /usr/share/perl/5.18/CPAN/Distribution.pm line 468.
  • imagemagick

Hubert Schölnast's user avatar

  • I know this is old, and I don't know if it will help or even if you still have the issue, but ... I was having the same error, and found that the solution wasn't with cpan, but to install perlmagick: sudo apt-get install perlmagick After that, I could use Image::Magick in my Perl scripts. –  AntonH Sep 17, 2015 at 4:29
  • 1 It is not old. I still can't install Image::Magick. I tried to install perlmagick, but i got the message, that I still have the newest version installed. –  Hubert Schölnast Sep 17, 2015 at 10:24
  • 1 I'm sorry I can't help more :( I had checked my installation of ImageMagick with sudo apt-get install imagemagick and it told me I had latest version installed (version with Ubuntu 14.04 desktop; I don't know if version between server and desktop is different, or if server doesn't provide dev files). Didn't install and PHP5 modules, and I couldn't find the ImageMagick.h files on my system. Good luck. If I find something I'll check back in. –  AntonH Sep 17, 2015 at 17:15

5 Answers 5

Diego's solution works.

A similar procedure has worked for me for versions ImageMagick-6.9.1 and ImageMagick-6.9.5.

Build Image::Magick perl module from source

Go to: http://www.imagemagick.org/script/download.php

Download a tar.gz file from one of the mirrors:

Extract into ~/home/src:

Configure Image Magic with Perl Bindings

Make sure perl dev files are installed

Install Image Magick

Check that it works:

Hoe-Kit's user avatar

My final solution installing Image magick was:

(After trying all your steps)

Download current version of ImageMagick from the source

6.9.2 in my case:

After the download, switch to the Download folder and:

and then all goes smoothly

(*) another missing part, lperl , so in the process I have to add: sudo apt-get install libperl-dev

hg8's user avatar

Install the package php5-imagick and try installing via CPAN again.

earthmeLon's user avatar

  • I'm not using php on my server, but I followed you advise and installed php5-imagick. The result: nothing changed. The installation of the cpan-modul still throws the same error. –  Hubert Schölnast May 22, 2015 at 19:54
  • Thanks for trying. I've had CPAN issues that relied on my installing PHP packages before. Sorry it didn't help in this case. My only other recommendation would be to upgrade CPAN itself via CPAN. –  earthmeLon May 22, 2015 at 19:56
  • I executed cpan-outdated -p | cpanm immediately before I tried to install Image::Magick. I think this should also have updated cpan itself. –  Hubert Schölnast May 22, 2015 at 20:02
  • It's looking for imagemagick devel headers - did you verify you have those installed? –  Thomas Ward ♦ May 23, 2015 at 21:47

Try to install headers:

Along with -dev packages:

Eugen Konkov's user avatar

Obviously the perl-lib is less thoroughly maintained than the Ubuntu repos.

Fixed it for while cpanm failed.

Max's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged imagemagick cpan ..

  • The Overflow Blog
  • Climbing the GenAI decision tree sponsored post
  • Diverting more backdoor disasters
  • Featured on Meta
  • New Focus Styles & Updated Styling for Button Groups
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network
  • AI-generated content is not permitted on Ask Ubuntu
  • Let's organize some chat workshops

Hot Network Questions

  • Homemade garlic salt - risk of botulism?
  • Are all arguments for the existence of other minds circular?
  • What other terms have been used to describe storing working data permanently besides "save"?
  • Position of the text within a table
  • Recycle buying soda problem
  • A version of Hilbert's Nullstellensatz for real zeros
  • What fauna can survive a permanently dark sky?
  • How do I attach this master link on the chain?
  • How can complement of the Cantor set be the countable union of open intervals?
  • Help designing a manual reset circuit
  • What is this no-harness rappel called?
  • How to say politely not to doze off during progress meeting?
  • Why is there increased fear of Russia's attack against Latvia, Lithuania, Estonia after the invasion of Ukraine started?
  • Why doesnt DFT Padding cause sinc like features
  • Why is there a year 1 B.C., a year 0, and a year 1 A.D. in NASA’s Five Millennium Canon of Solar Eclipses?
  • Old sci-fi episode/movie: man on a spaceship replaced his dead wife and kids with robot replicas
  • What animals would herbivorous humans most likely domesticate?
  • Why is inner model theory evidence for consistency of large cardinals?
  • heights of ideal classes and reduction theory for Bhargava cubes
  • Can motion be oscillatory but not periodic?
  • Output a 1-2-3 sequence
  • Maximum number of trailing zeros
  • Is there something between Debug and Release build?
  • Book recommendations for Combinatorics for Computer Science Students

assignment makes integer from pointer without a cast enabled by default

IMAGES

  1. Array : Assignment makes integer from pointer without a cast [-Wint

    assignment makes integer from pointer without a cast enabled by default

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

    assignment makes integer from pointer without a cast enabled by default

  3. [Solved] Assignment makes integer from pointer without a

    assignment makes integer from pointer without a cast enabled by default

  4. assignment makes integer from pointer without a cast

    assignment makes integer from pointer without a cast enabled by default

  5. C : warning: assignment makes pointer from integer without a cast

    assignment makes integer from pointer without a cast enabled by default

  6. iphone

    assignment makes integer from pointer without a cast enabled by default

VIDEO

  1. 3 pointer without super 💀 #brawlstars #supercell #shorts

  2. HOW TO DOWNLOAD AND PLAY (ONE PIECE DREAM POINTER) NO CHINESE ID AND PHONE NUMBER REQUIRED!

  3. Is Xfinity Stream cast enabled?

  4. How To Remove Realme touch pointer

  5. Left Right Game Pt.1

  6. Integrate 0 to 1.5 [x] dx I integration of greatest integer function x I Class 12

COMMENTS

  1. C pointers and arrays: [Warning] assignment makes pointer from integer

    [Warning] assignment makes pointer from integer without a cast [enabled by default] For line number 9 (ap = a[4];) and the terminal crashes. If I change line 9 to not include a position (ap = a;) I don't get any warnings and it works.

  2. Makes Integer From Pointer Without A Cast (Resolved)

    Converting Integers to Pointers {#converting-integers-to-pointers} To convert an integer to a pointer, follow these steps: Include the <stdint.h> header (C) or the <cstdint> header (C++) in your program. Cast your integer to the required pointer type using a double cast. int a = 42; uintptr_t int_ptr = (uintptr_t)&a;

  3. Assignment makes integer from pointer without a cast in c

    In this simple code we have three variables, an integer pointer "ptr", and two integers "n1" and "n2". We assign 2 to "n1", so far so good, then we assign the address of "n2" to "ptr" which is the suitable storing data type for a pointer, so no problems untill now, till we get to this line "n2 = ptr" when we try to assign "ptr" which is a memory address to "n2" that needs to store an integer ...

  4. [SOLVED] C

    Re: C - assigment makes integer from pointer without a cast warning. path [1] is the second element of a char array, so it's a char. home is a char *, i.e. a pointer to a char. You get the warning because you try to assign a char* to a char. Note also the potential to overflow your buffer if the content of the argv [1] argument is very long.

  5. What is Assignment Makes Pointer From Integer Without A Cast and How

    Decoding the Warning: Assignment Makes Pointer from Integer Without a Cast. The warning "assignment makes pointer from integer without a cast" is a compiler message that indicates a potential issue in your code. It occurs when an integer value is assigned to a pointer variable without explicitly casting the integer to a pointer type.

  6. C error

    When I try to compile the program I get the following messages in the terminal: jharvard@appliance (~/Dropbox/prg): gcc n.c -o n. n.c: In function 'main': n.c:14:18: warning: assignment makes integer from pointer without a cast [enabled by default] firstInitial = "J"; ^. n.c:15:19: warning: assignment makes integer from pointer without a cast ...

  7. C : warning: assignment makes pointer from integer without a cast

    c: C : warning: assignment makes pointer from integer without a cast [enabled by default]Thanks for taking the time to learn more. In this video I'll go thro...

  8. Assignment makes pointer from integer without a cast

    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

  9. assignment makes pointer from integer without a cast [enabled by default]

    The warning is: Code: file.c: In function 'main': file.c:16:10: warning: assignment makes pointer assignment makes pointer from integer without a cast [enabled by default] Latest LQ Deal: Latest LQ Deals

  10. c

    1. Earlier, I asked a similar question, but I've since changed my code. Now the compiler gives me a different warning. This is an example of what my code looks like now: void *a = NULL; void *b = //something; a = *(int *)((char *)b + 4); When I try to compile, I get "warning: assignment makes pointer from integer without a cast."

  11. 问题:warning: assignment makes integer from pointer without a cast

    C语言在编译过程中有时候会报警告:. warning: assignment makes integer from pointer without a cast [enabled by default] 这个警告其实不会导致系统运行出错,警告的意思是赋值类型和变量类型不一致导致的。. 在这个问题中一般出现的地方如下:. tempStruct *temp = tempStructGet ...

  12. can't install cpan module Image::Magick

    SvIV(ST(i)) : ParseCommandOption( ^ Magick.xs:3548:19: warning: assignment makes integer from pointer without a cast [enabled by default] op=(ComplexOperator) in; ^ Magick.xs:3548:38: error: expected ';' before 'in' op=(ComplexOperator) in; ^ Magick.xs:3563:5: warning: implicit declaration of function 'ComplexImages' [-Wimplicit ...

  13. assignment makes integer from pointer without a cast

    When compiling the code it gave warnings and errors: network.c:51:12: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] network.c:60:12: warning: assignment makes integer from pointer without a cast [enabled by default] network.c:64:26: error: invalid type argument of unary '*' (have 'int ...

  14. assignment makes integer from pointer without a cast [enabled by default]|

    assignment makes integer from pointer without a cast [enabled by default]|. Two sets of errors, and I'm lost. Before you ask-I have spent an upwards of 10 hrs per day for the last 4 days re-reading the absolute beginners guide and c programming books from my class. If anyone can simplify this for me, I'd be so grateful.

  15. Solved multiple_wordcount.c:30:9: warning: assignment makes

    Engineering. Computer Science. Computer Science questions and answers. multiple_wordcount.c:30:9: warning: assignment makes integer from pointer without a cast [enabled by default] pid = (int*) malloc ( (argc-1)*sizeof (int)); 17 int count_words (char *filename, int ppid); 18 19 int main (int argc, char **argv) 20 { 21 //to store process id of ...

  16. assignment makes integer from pointer without a cast

    text should be declared as: char *text = NULL; You need a pointer to char. This pointer can be set to point to any literal string (as you do in your case statements). char text; // this is just a single character (letter), not a string. Objective_Ad_4587 • 3 yr. ago. i got it thank you very much.

  17. Solved I'm getting this warning when I try to compile the

    I'm getting this warning when I try to compile the code below. 11:5 warning: assignment makes pointer from integer without a cast [enabled by default] ptr = strtok (str, " "); The language is in C and I'm using the newest version of Ubuntu. Here's the best way to solve it.

  18. C

    3. result = s1. result is an int, integer. s1 is a char const*, a const pointer to char. You can't assign the value of a const char* to an integer (because they might not have the same size for example). You can however, as hinted by the warning, cast the value to the correct type to force it to stop warning you: result = (int)s1;

  19. assignment makes integer from pointer without a cast

    assignment makes integer from pointer without a castc/c++ warning explained#syntax #c/c++ #compiler #error #warning