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 Ubuntu Cinnamon
  • Get Edubuntu
  • Get Ubuntu Unity
  • 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

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.

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 To Paste The Same Thing In Multiple Cells

How To Paste The Same Thing In Multiple Cells

Rainbow Six Siege Error Code 6-0x00000001

Rainbow Six Siege Error Code 6-0x00000001

How To Play Four-Player Zombies On Black Ops

How To Play Four-Player Zombies On Black Ops

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

  • About JOE TECH
  • Privacy Policy

Home Posts Topics Members FAQ

Sign in to post your reply or Sign up for a free account.

Similar topics

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use .

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.

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
  • warning assignment makes interger from pointer without cast
  • Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems

Thread: warning assignment makes interger from pointer without cast

Thread tools.

  • Show Printable Version
  • Email this Page…
  • Subscribe to this Thread…
  • View Profile
  • View Forum Posts

cooper1200 is offline

but here is the rub ..... if i do this Code: int main() { int i; char mystring[2][10] = {"hello you", "bye you"}; for (i = 0; i <2; i++) { printf("%s\n", mystring[i]); } } its as happy as anything and i get the obvious output however if i then change it to this Code: int main() { int i; char mystring[2][10] = {"hello you", "bye you"}; for (i = 0; i <2; i++) { printf("enter upto 8 characters"); scanf(" %s", &mystring[i]); } } i get more warnings than i know what to do with coop
  • Visit Homepage

laserlight is offline

What are the warnings? What %s with scanf expect?
Originally Posted by Bjarne Stroustrup (2000-10-14) I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool. Look up a C++ Reference and learn How To Ask Questions The Smart Way
format %s expects argument of type char * but argument 2 has type char [*][10] if i change mystring[2][10] to *mystring[2][10] i get the same warning except its char [**][10]
Originally Posted by cooper1200 if i change mystring[2][10] to *mystring[2][10] Why did you do that? This is very important. You cannot program blindly. So why?
because it wanted a pointer right???
Originally Posted by cooper1200 because it wanted a pointer right??? Sure, so you randomly insert a & here or a * there and maybe the stars will align and the code will compile and run with the correct result. What are you, an alchemist? I suggest adding heartsbane of great silver wolf to get "the pointer". Remember to stir the cauldron exactly 47 times, clockwise. No, you know that it wants a char*. You also know that in most contexts, an array of char is converted to a pointer to its first element. So, figure it out. Stop guessing. Originally Posted by cooper1200 if i change mystring[2][10] to *mystring[2][10] i get the same warning except its char [**][10] Wait, you mean you changed the declaration of mystring? Look, you need to think, not change the code blindly hoping that it'll work. Originally Posted by cooper1200 format %s expects argument of type char * but argument 2 has type char[*][10] This is definitely not the error message. Argument 2 has type char (*)[10], i.e., pointer to an entire array of 10 char. Go back to the basics. Write a program that requests for the user's name and reads it as a string into an array of char using scanf and %s, then prints out a hello greeting with the user's name. This is like the second or third program beginners might write, and you need to be able to write it correctly before moving on to 2D arrays.
Last edited by laserlight; 05-04-2019 at 07:54 PM .
that is exactly what i was trying to do when i got he error message it said and u said it wanted a pointer so it wasn't blind faith i gave it a pointer and it still wasn't happy
also where in the above examplles have i decalered any strings as type int
Originally Posted by cooper1200 that is exactly what i was trying to do when i got he error message it said and u said it wanted a pointer so it wasn't blind faith i gave it a pointer and it still wasn't happy That's like saying "the cab driver wanted US dollar, so I gave them US dollar, but they still weren't happy". Of course they weren't happy! You were supposed to pay 50 USD for the cab fare, not 5 USD! You have to pay attention to the pointer type, not just say "I'm passing a pointer when a pointer is needed, so it is alright". Passing a char(*)[10] when a char* is expected doesn't cut it. Originally Posted by cooper1200 also where in the above examplles have i decalered any strings as type int You passed a char as an argument, and this was promoted to int.
i can be so thick at times i need shot Code: #include <stdio.h> #include <stdlib.h> #include <string.h> void put_info(char names[][4][20], char info[], int i, int j); void get_info(char names [][4][20], int i, int j); int main() { int i, j; char names[2][4][20]; for (j = 0; j < 2; j++) { for (i = 0; i < 4; i++) { get_info(names, i, j); } } for (j = 0; j < 2; j++) { for (i = 0; i < 4; i++) { printf("%s\t\t\t", names[j][i]); } printf("\n"); } } void get_info(char names [][4][20], int i, int j) { char info[20]; switch(i) { case 0: printf("enter first name: "); scanf(" %s", info); break; case 1: printf("enter second name: "); scanf(" %s", info); break; case 2: printf("enter address: "); scanf(" %s", info); break; case 3: printf("enter phone number: "); scanf(" %s", info); break; } put_info(names, info, i, j); } void put_info(char names[][4][20], char info[], int i, int j) { strcpy(names[j][i], info); } coop
how many times have i been told and read that when dealing with strings the variable name is the pointer so a call of scanf doesn't need another pointer the variable name is the pointer ie variable_name rather than & variable_name. When passing arrays the left most size is omitted in the function deceleration ie myarray[] if 1d myarray[][2] for 2d and myarray[][2][4] for 3d array etc. Please feel free to beat me round the head with a 2x4 next time. thanks for all your patience coop
Good to see that you've got it. By the way, I would avoid 3D arrays unless I really have to have them: consider introducing a struct as an abstraction, e.g., Code: struct Contact { char first_name[20]; char second_name[20]; char address[20]; char phone_number[20]; }; // ... struct Contact contacts[2]; You might no longer be able to do your indexing trick with put_info and get_info, but it'll be easier to understand and hence easier to debug and maintain in the long run.

First

  • Jump to page:
  • 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

[need help]warning: assignment makes integer from pointer without a cast, warning: 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, tags for this thread.

View Tag Cloud

  • C and C++ Programming at Cprogramming.com
  • Web Hosting
  • Privacy Statement

IMAGES

  1. assignment makes integer from pointer without a cast

    c programming warning assignment makes integer from pointer without a cast

  2. [Solved] C pointers and arrays: [Warning] assignment

    c programming warning assignment makes integer from pointer without a cast

  3. C : warning: assignment makes pointer from integer without a cast [enabled by default]

    c programming warning assignment makes integer from pointer without a cast

  4. c assignment makes integer from pointer without a cast

    c programming warning assignment makes integer from pointer without a cast

  5. Warning : passing argument 1 of 'printf' make pointer from integer

    c programming warning assignment makes integer from pointer without a cast

  6. Assignment makes integer from pointer without a cast in c : u/coderlegion

    c programming warning assignment makes integer from pointer without a cast

VIDEO

  1. Why Pointers are Dangerous in C / C++? #cpp #cplusplus #programming #code

  2. C Programming Interview Question

  3. size of int and int pointer and why #cprogramming #programming

  4. Integer Character and Float Pointer in C

  5. initialization from incompatible pointer type

  6. Array of Pointers in C-Language Practical

COMMENTS

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

    In this case a[4] is the 5th integer in the array a, ap is a pointer to integer, so you are assigning an integer to a pointer and that's the warning. So ap now holds 45 and when you try to de-reference it (by doing *ap) you are trying to access a memory at address 45, which is an invalid address, so your program crashes.. You should do ap = &(a[4]); or ap = a + 4;

  2. Assignment makes pointer from integer without cast

    However, this returns a char. So your assignment. cString1 = strToLower(cString1); has different types on each side of the assignment operator .. you're actually assigning a 'char' (sort of integer) to an array, which resolves to a simple pointer. Due to C++'s implicit conversion rules this works, but the result is rubbish and further access to ...

  3. c

    The warning comes from the fact that you're dereferencing src in the assignment. The expression *src has type char, which is an integral type.The expression "anotherstring" has type char [14], which in this particular context is implicitly converted to type char *, and its value is the address of the first character in the array.So, you wind up trying to assign a pointer value to an integral ...

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

    Case 1: Assignment of a pointer to an integer variable. n1 = 2; ptr = &n1; n2 = ptr; /* Failure in this line */. In this simple code we have three variables, an integer pointer "ptr", and two ...

  5. [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.

  6. Warning: Assignment Makes Pointer From Integer Without A Cast [enabled

    This guide will walk you through the process of resolving the "Warning: Assignment Makes Pointer from Integer Without a Cast [Enabled by Default]" error in C programming.

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

  8. warning: assignment makes pointer from integer without a cast

    Warning: assignment makes integer from pointer without a cast. By Nutshell in forum C Programming. Replies: 3. Last Post: 01-14-2002, 12:13 PM. Code: #include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <errno.h> int main (int argc,char **argv) { char c.

  9. warning: assignment makes integer from pointer without a cast

    YAY! Exactly the kind of attidude we want to see among newcomers! As for qqqqxxxx; You are in no way at all helping a person by doing their whole homework!

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

    Related to C: warning assignment makes integer from pointer without a cast 1. What does the warning "assignment makes integer from pointer without a cast" mean? This warning indicates that a pointer value is being assigned to an integer variable without being explicitly converted or casted. This can create unexpected behavior and should be ...

  11. 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;

  12. warning: assignment makes integer from pointer without a cast

    C Programming; warning: assignment makes integer from pointer without a cast; Getting ... Thread: warning: assignment makes integer from pointer without a cast. Thread Tools. Show Printable Version ... View Forum Posts Registered User Join Date Aug 2009 Posts 192. warning: assignment makes integer from pointer without a cast So im not really ...

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

  14. 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."

  15. Warning: assignment makes integer from pointer without a cast

    Hey everybody. I'm trying to make a simple calculator program and I got "warning: assignment makes integer from pointer without a cast" four times on lines 17, 19, 21, and 23. Here's the source. I have no clue what the problem is. Can someone help? 1. operate is an integer. 2. "+" is a string.

  16. warning: assignment makes integer from pointer without a cast

    driver.c:49: warning: assignment makes integer from pointer without a cast driver.c:50: warning: assignment makes integer from pointer without a cast driver.c:51: warning: assignment makes integer from pointer without a cast getparams.c: In function `getparams': getparams.c:8: warning: assignment makes pointer from integer without a cast

  17. warning: assignment makes integer from pointer without a cast

    Hi, If I don't include <libgen.h> I get then warnig below in regcmp call: warning: improper pointer/integer combination: op "=" but if I include it the warning is not shown, but them program... C / C++. 2. warning: passing arg 1 of `atoi' makes pointer from integer without a cast.

  18. warning: assignment makes integer from pointer without a cast

    C Programming; warning: assignment makes integer from pointer without a cast; ... Thread: warning: assignment makes integer from pointer without a cast. Thread Tools. Show Printable Version ... Registered User Join Date Dec 2008 Posts 2. warning: assignment makes integer from pointer without a cast Here is the code I wrote to detect whether a ...

  19. 问题: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 ...

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

  21. warning assignment makes interger from pointer without cast

    C Programming; warning assignment makes interger from pointer without cast; Getting started with C or C++ | C Tutorial | C++ Tutorial ... warning: assignment makes pointer from integer without a cast. By kiros88 in forum C Programming Replies: 4 Last Post: 03-03-2010, 01:06 PM.