Solving Assignment Makes Integer from Pointer Without a Cast in C: Tips and Solutions

David Henegar

As a developer, encountering errors while coding is inevitable. One common error that C programmers come across is the "assignment makes integer from pointer without a cast" error. This error message can be frustrating and time-consuming to resolve, but with the right tips and solutions, it can be easily fixed.

Understanding the Error Message

Before we dive into the tips and solutions for fixing this error, let's first understand what it means. The "assignment makes integer from pointer without a cast" error occurs when a pointer is assigned to an integer without a proper type cast. This error message is often accompanied by a warning message that looks like this:

This warning message is telling the programmer that the code is trying to assign a pointer value to an integer variable without casting the pointer to the correct type.

Tips for Fixing the Error

Here are some tips to help you fix the "assignment makes integer from pointer without a cast" error:

Tip #1: Check Your Pointer Types

Make sure that the pointer you are trying to assign to an integer variable is of the correct data type. If the pointer is pointing to a different data type, you will need to cast it to the correct type before assigning it to the integer variable.

Tip #2: Use the Correct Syntax

When casting a pointer to a different data type, make sure to use the correct syntax. The syntax for casting a pointer to an integer is (int) pointer .

Tip #3: Use the Correct Assignment Operator

Make sure that you are using the correct assignment operator. The assignment operator for pointers is = while the assignment operator for integers is == .

Tip #4: Check Your Code for Errors

Double-check your code for errors. Sometimes, the "assignment makes integer from pointer without a cast" error can be caused by a syntax error or a missing semicolon.

Solutions for Fixing the Error

Now that you have some tips for fixing the "assignment makes integer from pointer without a cast" error, let's look at some solutions.

Solution #1: Cast the Pointer to the Correct Type

To fix this error, you need to cast the pointer to the correct type before assigning it to the integer variable. Here's an example:

In this example, the pointer is cast to an integer using the (int) syntax before it is assigned to the num variable.

Solution #2: Declare the Integer Variable as a Pointer

Another solution is to declare the integer variable as a pointer. Here's an example:

In this example, the num variable is declared as a pointer, and the ptr variable is assigned to it without casting.

Q1: What causes the "assignment makes integer from pointer without a cast" error?

A: This error occurs when a pointer is assigned to an integer variable without being cast to the correct data type.

Q2: How do I cast a pointer to an integer in C?

A: To cast a pointer to an integer in C, use the (int) syntax.

Q3: Why is my code still giving me the same error message even after I cast the pointer to the correct type?

A: Double-check your code for syntax errors and missing semicolons. Sometimes, these errors can cause the same error message to appear even after you have cast the pointer to the correct type.

Q4: Can I declare the integer variable as a pointer to fix this error?

A: Yes, you can declare the integer variable as a pointer to fix this error.

Q5: What is the correct assignment operator for pointers and integers in C?

A: The assignment operator for pointers is = while the assignment operator for integers is == .

The "assignment makes integer from pointer without a cast" error can be frustrating, but with the right tips and solutions, it can be easily fixed. By understanding the error message and following the tips and solutions provided in this guide, you can resolve this error and improve the functionality of your code.

Related Links

assignment makes integer from pointer without a cast meaning

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.

  • Intro Physics Homework Help
  • Advanced Physics Homework Help
  • Precalculus Homework Help
  • Calculus Homework Help
  • Bio/Chem Homework Help
  • Engineering Homework Help

Follow along with the video below to see how to install our site as a web app on your home screen.

Note: This feature may not be available in some browsers.

  • Homework Help
  • Engineering and Comp Sci Homework Help

C: warning assignment makes integer from pointer without a cast

  • Thread starter eatsleep
  • Start date Sep 13, 2013
  • Tags Assignment Integer
  • Sep 13, 2013

A PF Electron

  • Unconventional interface superconductor could benefit quantum computing
  • Langbeinites show talents as 3D quantum spin liquids
  • New 'chiral vortex' of light allows chemists to 'see' molecules through the mirror

"RED" is not a character variable - it is a string. The pointer conversion is from the string pointer.  

A PF SuperCluster

A pf planet.

jedishrfu said: choice should be defined as: char *choice;
D H said: That should be const char* choice , not just char* choice . Assigning to a pointer to a string such as "RED" is illegal (undefined behavior), so it's best to make the pointer a type that does not accept assignments.
jedishrfu said: Doesn't this depend on what he's trying to do? Suppose this choice is in some sort of input loop where first its RED and then its BLUE ...
D H said: Assigning to a pointer to a string such as "RED" is illegal (undefined behavior), so it's best to make the pointer a type that does not accept assignments.
D H said: There's nothing wrong with that. const char * choice (or char const * choice , same thing) means that choice can be used on the left hand side of an assignment statement but that choice[1] cannot. You are apparently thinking of char * const choice = "RED"; , but that's a completely different data type. With this declaration, choice can only be assigned a value in the declaration statement. However, choice[1]='D'; is perfectly legal with this declaration. You can combine the two restrictions with the declaration const char * const choice = "RED";
  • Sep 14, 2013
rcgldr said: It's my understanding that literal strings are like statics, and exist from start to termination of a program, so why should assigning a pointer to a literal string be undefined? Trying to change a value in the literal string via the pointer would be illegal / undefined behavior, but the pointer assignment shouldn't be an issue.
nsaspook said: It depends on the computer architecture and how strict the compiler is.
rcgldr said: The point I was making is how string literals are defined in the C89 and later standards. From the C89 standard, section 3.1.4: ... So it would seem that only an attempt to modify a string is undefined, not the usage of a pointer to access a literal string. The type "array of char" or "array of wchar_t" would be the same regardless of where the string literal was stored (ROM, RAM, code section of a program, ... ).
D H said: I wasn't clear with my previous post. There's nothing wrong per se with char* ptr; ...; ptr="RED"; ...; ptr="BLUE"; What's wrong is assigning into that pointer: *ptr = 'A'; . What's worse is that most compilers won't report this as an error. You don't find out until runtime. Declaring the variable as a const char* pointer (or char const* , same thing) and assignments such as ptr="RED"; are still legal, but now *ptr = 'A'; becomes a compile-time error.

Related to C: warning assignment makes integer from pointer without a cast

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

In C, pointers are used to store memory addresses of variables or data. Assigning a pointer value to an integer variable can result in loss of information or incorrect memory access, which is why the compiler issues this warning.

To fix this warning, you can use a typecast to explicitly convert the pointer value to an integer before assigning it to the variable. However, make sure that the conversion is appropriate and does not cause any loss of information.

While this warning may not always result in errors, it can lead to unexpected behavior and should be addressed. Ignoring this warning can potentially cause issues in your program, so it is best to fix it.

In some cases, using a different data type for the variable may be a better solution than using a typecast. For example, if the pointer is pointing to a string, you can use a string data type instead of converting it to an integer.

Similar threads

  • Nov 10, 2015
  • Apr 5, 2011
  • Oct 14, 2020
  • Jun 11, 2017
  • Feb 9, 2020
  • Jan 30, 2015
  • Jul 19, 2019
  • Sep 16, 2014
  • May 26, 2015
  • May 9, 2017

Hot Threads

  • Engineering   Help Calculating Length And Position Of Connections On Rotating Object
  • Comp Sci   Training YOLOv9 on custom dataset
  • Engineering   H-parameter model for non-inverting amplifier
  • Engineering   Negative PSRR of the Two-Stage Op Amp
  • Second order differential - Tanks in series cooling coil

Recent Insights

  • Insights   PBS Video Comment: “What If Physics IS NOT Describing Reality”
  • Insights   Aspects Behind the Concept of Dimension in Various Fields
  • Insights   Views On Complex Numbers
  • Insights   Addition of Velocities (Velocity Composition) in Special Relativity
  • Insights   Schrödinger’s Cat and the Qbit
  • Insights   The Slinky Drop Experiment Analysed

C Board

  • Today's Posts
  • 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 integer from pointer 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: Warning: assignment makes integer from pointer without a cast

Thread tools.

  • Show Printable Version
  • Email this Page…
  • Subscribe to this Thread…

Search Thread

  •   Advanced Search
  • Linear Mode
  • Switch to Hybrid Mode
  • Switch to Threaded Mode
  • View Profile
  • View Forum Posts

Babkockdood is offline

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. Code: #include <stdio.h> #include <stdlib.h> int main() { int int1; int operate; int int2; int presult = (int1 + int2); int mresult = (int1 - int2); int xresult = (int1 * int2); int dresult = (int1 / int2); printf("Input: "); scanf("%i%s%i", &int1, &operate, &int2); if (operate = "+") printf("Result: %i\n", presult); if (operate = "-") printf("Result: %i\n", mresult); if (operate = "*") printf("Result: %i\n", xresult); if (operate = "/") printf("Result: %i\n", dresult); return 0; } I have no clue what the problem is. Can someone help?

quzah is offline

1. operate is an integer. 2. "+" is a string. 3. = is assignment. 4. == is an equality test. 5. You can't test strings for equality using ==. 6. You can't assign strings to integers. Quzah.
Hope is the first step on the road to disappointment.
OK, I replaced int operate; with char *operate; and it compiled without error. But when I start it, I get "Floating point exception".
Last edited by Babkockdood; 04-24-2010 at 04:40 PM .

kermit is offline

Originally Posted by Babkockdood OK, I replaced int operate; with char *operate; and it compiled without error. But when I start it, I get "Floating point exception". For one thing, that does not allocate any actual space for whatever string scanf might read in. I doubt that making just one change would allow it to compile without error. What compiler are you using, and what sort of warnings have you got turned on. What does your updated code look like now?
Last edited by kermit; 04-24-2010 at 04:53 PM .
  • 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

Memory issue, looking for constructive criticism, assignment makes pointer from integer, interface question.

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

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…
  • Linear Mode
  • Switch to Hybrid Mode
  • Switch to Threaded Mode
  • 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

Home Posts Topics Members FAQ

New Member |Select|Wrap|Line Numbers It comes from the line 32. Any help that helps me fix this problem and understand why it has arisen is appreciated.

Thanks 3593 Recognized Expert Top Contributor
Message
 

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

Similar topics

| last post by:
| last post by:
| last post by:
| last post by:
| last post by:
| last post by:
| last post by:
| last post by:
| last post by:
| last post by:
| last post by:
| last post by:
| last post by:
| last post by:

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.

The Place to Start for Operating System Developers

Skip to content

  • Unanswered topics
  • Active topics
  • Board index Everything Else General Programming
  • Search Advanced search

What is assignment makes pointer from integer without a cast

Post by NunoLava1998 » Wed Dec 07, 2016 4:40 am

Code: Select all

Re: What is assignment makes pointer from integer without a

Post by Kevin » Wed Dec 07, 2016 4:53 am

Post by NunoLava1998 » Wed Dec 07, 2016 4:59 am

Kevin wrote: key is a const char* (i.e. a pointer type) whereas kbdus[scancode] is an unsigned char (i.e. an integer type). These are fundamentally different types, so the compiler thinks chances are that the assignment is wrong. And the compiler is right, kbdus[scancode] doesn't contain integers that make sense as a pointer. If you want a string, you need to create one. That is, you need some memory where you can put the character and a '\0' byte. Maybe in this case a local char array of size 2 is what you want.

Post by Ycep » Wed Dec 07, 2016 5:14 am

Post by NunoLava1998 » Wed Dec 07, 2016 5:25 am

Lukand wrote: Please, learn C already... This is probably what you wanted: Code: Select all void kbdhandler() { unsigned char scancode, key; scancode = inb(0x60); key = kbdus[scancode]; terminal_writestring(key); } Making mistakes like this one would lead you nowhere in operating system development, as in algorithmic programming, general programming, game programming, etc.

User avatar

Post by iansjack » Wed Dec 07, 2016 5:44 am

Post by NunoLava1998 » Wed Dec 07, 2016 6:29 am

iansjack wrote: Why are you using a string writing function to write a character? Just program a function that writes a single character to the screen.

Post by iansjack » Wed Dec 07, 2016 6:38 am

Post by NunoLava1998 » Wed Dec 07, 2016 6:46 am

iansjack wrote: It's kind of you to offer me the chance to debug your code but I'm afraid I must decline the offer.

User avatar

Post by Solar » Wed Dec 07, 2016 7:16 am

Post by Kevin » Wed Dec 07, 2016 7:59 am

NunoLava1998 wrote: Beacuse terminal_write won't work and terminal_putchar puts the letter that is pressed into every single slot of the screen for some reason.
How do i do it? If i try to change kbdus from unsigned char to const char *, this happens

User avatar

Post by Octacone » Wed Dec 07, 2016 11:22 pm

Post by onlyonemac » Thu Dec 08, 2016 2:25 am

Post by NunoLava1998 » Thu Dec 08, 2016 5:37 am

Post by iansjack » Thu Dec 08, 2016 5:51 am

NunoLava1998 wrote: I need to know how to halt until a key is pressed.

Return to “General Programming”

  • Operating System Development
  • ↳   OS Development
  • ↳   OS Design & Theory
  • ↳   Announcements, Test Requests, & Job openings
  • Everything Else
  • ↳   General Programming
  • ↳   General Ramblings
  • ↳   Auto-Delete Forum
  • ↳   OSDev Wiki
  • ↳   About this site
  • Board index
  • Delete cookies

Flat Style by Ian Bradley

Powered by phpBB ® Forum Software © phpBB Limited

Privacy | Terms

assignment makes integer from pointer without a cast meaning

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

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

Get early access and see previews of new features.

initialization makes integer from pointer without a cast [enabled by default]

i just started to learn how to program and i encountered this error that goes like this: "initialization makes integer from pointer without a cast [enabled by default]" What is the problem?

Davinci3f's user avatar

  • 2 Whatever you do DO NOT ADD A CAST !! The error message could be improved a lot :) –  pmg Commented May 4, 2014 at 19:13
  • //Not efficient, but it does work - this suggests that you are already worrying about efficiency. Don't! At least not while you're an absolute beginner. –  The Paramagnetic Croissant Commented May 4, 2014 at 19:16

4 Answers 4

The problem is with char Hero1 = "Batman" :

  • When you use a double-quoted string of characters in your code, the compiler replaces it with a pointer to the beginning of the memory space in which the string will reside during runtime.
  • So by char Hero1 = "Batman" , you are actually attempting to assign a memory address (which typically consists of 32 or 64 bits of data, depending on your system) into a character variable (which typically stores 8 bits of data).

In order to fix the problem, you need to change it to either one of the following options:

  • char Hero1[] = "Batman"
  • char* Hero1 = "Batman"

FYI, in both cases above, the string "Batman" will reside in a read-only memory section during runtime.

However, there is a notable difference between these two cases:

  • Using char Hero1[] , the "Batman" string will be copied into the stack every time the function is called. The Hero1 array will start at that address, and you will be able to change the contents of that array at a later point within the function.
  • Using char* Hero1 , the "Batman" string will not be copied into the stack every time the function is called. The Hero1 variable will be pointing to the original address of the string, hence you will not will be able to change the contents of that string at any point within the function.

When the executable image is generated from your code, the string is placed in the code-section, which is one of several memory-sections within the program. The compiler then replaces the so-called "string assignment" with a so-called "integer assignment".

For example, char* x = "abc" is changed into char* x = (char*)0x82004000 before being compiled into object code, where 0x82004000 is the (constant) address of the string in the program's memory space.

When you do sizeof("abc") , the executable image will not even contain the "abc" string, since there is no "runtime" operation performed on this string.

There is no object code generated for sizeof - the compiler computes this value during compilation , and immediately replaces it with a constant .

You can look into the (intermediate) map file that is usually generated, and see that the input string of that sizeof operation does not appear anywhere.

BoltClock's user avatar

A couple times you have some issues:

You should define all of your vars at the top of the function, its a good C practice.

Other than that, I flagged the issues (and corrected them) with comments.

phyrrus9's user avatar

This error you get because String data type is not in C programming you can print string by using array or char pointer like

Click here to check the output of solution array

2. char pointer :

Click here to check the output of solution char pointer

akshay_mithari's user avatar

  • The first version is not correct. C will not null-terminate the array automatically. You need to do char a[] = {'a', 'b', 'c', 'd', 'f', '\0'}; –  costaparas Commented Dec 31, 2020 at 5:15
  • Also, please work on fixing the indentation and formatting of your answer. –  costaparas Commented Dec 31, 2020 at 5:16
  • sir first program shows why that error occurred in your program and the rest of two is the solution to resolve it –  akshay_mithari Commented Jan 17, 2021 at 17:32
  • I'm not the OP (this question was posted 6 years ago btw), I was commenting on this post since it was flagged as a low-quality answer, advising you to fix up the formatting in the answer . The bug I am referring to is for the solution you proposed using the array, which is invalid C, please check again. –  costaparas Commented Jan 18, 2021 at 1:18
  • sir all solutions are in working condition i also attached screenshots of my codes and output i checked that code on programiz C compiler and also changed format of my answer –  akshay_mithari Commented Jan 18, 2021 at 5:47

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged c or ask your own question .

  • The Overflow Blog
  • Ryan Dahl explains why Deno had to evolve with version 2.0
  • From PHP to JavaScript to Kubernetes: how one backend engineer evolved over time
  • Featured on Meta
  • We've made changes to our Terms of Service & Privacy Policy - July 2024
  • Bringing clarity to status tag usage on meta sites
  • Feedback requested: How do you use tag hover descriptions for curating and do...
  • What does a new user need in a homepage experience on Stack Overflow?

Hot Network Questions

  • If you get pulled for secondary inspection at immigration, missing flight, will the airline rebook you?
  • Can pedestrians and cyclists use the Channel Tunnel?
  • Is there anything that stops the majority shareholder(s) from destroying company value?
  • Everyone hates this Key Account Manager, but company won’t act
  • What's the counterpart to "spheroid" for a circle? There's no "circoid"
  • Calculate the sum of numbers in a rectangle
  • A binary sequence such that sum of every 10 consecutive terms is divisible by 3 is necessarily periodic?
  • Looking for title of a Ursula K. Le Guin story/novel that features four-way marriage/romantic relationships
  • Visualizing histogram of data on unit circle?
  • How to justify a ban on single-deity religions?
  • Has the government of Afghanistan clarified what they mean/intend by the ban on 'images of living beings'?
  • Should it be "until" or "before" in "Go home until it's too late"?
  • "Knocking it out of the park" sports metaphor American English vs British English?
  • \includegraphics not reading \newcommand
  • Fast circular buffer
  • Can I use rear (thru) axle with crack for a few rides, before getting a new one?
  • Postdoc supervisor has stopped helping
  • Does a visiting ranking officer on a Starfleet vessel assume command if the command staff of higher rank of the vessel are incapacitated?
  • Miracle Miracle Octad Generator Generator
  • How soon to fire rude and chaotic PhD student?
  • Should I be worried about this giant crack?
  • How can I address my colleague communicating with us via chatGPT?
  • Are there any virtues in virtue ethics that cannot be plausibly grounded in more fundamental utilitarian principles?
  • One IO to control two LEDs. When one is lit, the other is not

assignment makes integer from pointer without a cast meaning

Structured arrays #

Introduction #.

Structured arrays are ndarrays whose datatype is a composition of simpler datatypes organized as a sequence of named fields . For example,

Here x is a one-dimensional array of length two whose datatype is a structure with three fields: 1. A string of length 10 or less named ‘name’, 2. a 32-bit integer named ‘age’, and 3. a 32-bit float named ‘weight’.

If you index x at position 1 you get a structure:

You can access and modify individual fields of a structured array by indexing with the field name:

Structured datatypes are designed to be able to mimic ‘structs’ in the C language, and share a similar memory layout. They are meant for interfacing with C code and for low-level manipulation of structured buffers, for example for interpreting binary blobs. For these purposes they support specialized features such as subarrays, nested datatypes, and unions, and allow control over the memory layout of the structure.

Users looking to manipulate tabular data, such as stored in csv files, may find other pydata projects more suitable, such as xarray, pandas, or DataArray. These provide a high-level interface for tabular data analysis and are better optimized for that use. For instance, the C-struct-like memory layout of structured arrays in numpy can lead to poor cache behavior in comparison.

Structured datatypes #

A structured datatype can be thought of as a sequence of bytes of a certain length (the structure’s itemsize ) which is interpreted as a collection of fields. Each field has a name, a datatype, and a byte offset within the structure. The datatype of a field may be any numpy datatype including other structured datatypes, and it may also be a subarray data type which behaves like an ndarray of a specified shape. The offsets of the fields are arbitrary, and fields may even overlap. These offsets are usually determined automatically by numpy, but can also be specified.

Structured datatype creation #

Structured datatypes may be created using the function numpy.dtype . There are 4 alternative forms of specification which vary in flexibility and conciseness. These are further documented in the Data Type Objects reference page, and in summary they are:

A list of tuples, one tuple per field

Each tuple has the form (fieldname, datatype, shape) where shape is optional. fieldname is a string (or tuple if titles are used, see Field Titles below), datatype may be any object convertible to a datatype, and shape is a tuple of integers specifying subarray shape.

If fieldname is the empty string '' , the field will be given a default name of the form f# , where # is the integer index of the field, counting from 0 from the left:

The byte offsets of the fields within the structure and the total structure itemsize are determined automatically.

A string of comma-separated dtype specifications

In this shorthand notation any of the string dtype specifications may be used in a string and separated by commas. The itemsize and byte offsets of the fields are determined automatically, and the field names are given the default names f0 , f1 , etc.

A dictionary of field parameter arrays

This is the most flexible form of specification since it allows control over the byte-offsets of the fields and the itemsize of the structure.

The dictionary has two required keys, ‘names’ and ‘formats’, and four optional keys, ‘offsets’, ‘itemsize’, ‘aligned’ and ‘titles’. The values for ‘names’ and ‘formats’ should respectively be a list of field names and a list of dtype specifications, of the same length. The optional ‘offsets’ value should be a list of integer byte-offsets, one for each field within the structure. If ‘offsets’ is not given the offsets are determined automatically. The optional ‘itemsize’ value should be an integer describing the total size in bytes of the dtype, which must be large enough to contain all the fields.

Offsets may be chosen such that the fields overlap, though this will mean that assigning to one field may clobber any overlapping field’s data. As an exception, fields of numpy.object_ type cannot overlap with other fields, because of the risk of clobbering the internal object pointer and then dereferencing it.

The optional ‘aligned’ value can be set to True to make the automatic offset computation use aligned offsets (see Automatic byte offsets and alignment ), as if the ‘align’ keyword argument of numpy.dtype had been set to True.

The optional ‘titles’ value should be a list of titles of the same length as ‘names’, see Field Titles below.

A dictionary of field names

The keys of the dictionary are the field names and the values are tuples specifying type and offset:

This form was discouraged because Python dictionaries did not preserve order in Python versions before Python 3.6. Field Titles may be specified by using a 3-tuple, see below.

Manipulating and displaying structured datatypes #

The list of field names of a structured datatype can be found in the names attribute of the dtype object:

The dtype of each individual field can be looked up by name:

The field names may be modified by assigning to the names attribute using a sequence of strings of the same length.

The dtype object also has a dictionary-like attribute, fields , whose keys are the field names (and Field Titles , see below) and whose values are tuples containing the dtype and byte offset of each field.

Both the names and fields attributes will equal None for unstructured arrays. The recommended way to test if a dtype is structured is with if dt.names is not None rather than if dt.names , to account for dtypes with 0 fields.

The string representation of a structured datatype is shown in the “list of tuples” form if possible, otherwise numpy falls back to using the more general dictionary form.

Automatic byte offsets and alignment #

Numpy uses one of two methods to automatically determine the field byte offsets and the overall itemsize of a structured datatype, depending on whether align=True was specified as a keyword argument to numpy.dtype .

By default ( align=False ), numpy will pack the fields together such that each field starts at the byte offset the previous field ended, and the fields are contiguous in memory.

If align=True is set, numpy will pad the structure in the same way many C compilers would pad a C-struct. Aligned structures can give a performance improvement in some cases, at the cost of increased datatype size. Padding bytes are inserted between fields such that each field’s byte offset will be a multiple of that field’s alignment, which is usually equal to the field’s size in bytes for simple datatypes, see PyArray_Descr.alignment . The structure will also have trailing padding added so that its itemsize is a multiple of the largest field’s alignment.

Note that although almost all modern C compilers pad in this way by default, padding in C structs is C-implementation-dependent so this memory layout is not guaranteed to exactly match that of a corresponding struct in a C program. Some work may be needed, either on the numpy side or the C side, to obtain exact correspondence.

If offsets were specified using the optional offsets key in the dictionary-based dtype specification, setting align=True will check that each field’s offset is a multiple of its size and that the itemsize is a multiple of the largest field size, and raise an exception if not.

If the offsets of the fields and itemsize of a structured array satisfy the alignment conditions, the array will have the ALIGNED flag set.

A convenience function numpy.lib.recfunctions.repack_fields converts an aligned dtype or array to a packed one and vice versa. It takes either a dtype or structured ndarray as an argument, and returns a copy with fields re-packed, with or without padding bytes.

Field titles #

In addition to field names, fields may also have an associated title , an alternate name, which is sometimes used as an additional description or alias for the field. The title may be used to index an array, just like a field name.

To add titles when using the list-of-tuples form of dtype specification, the field name may be specified as a tuple of two strings instead of a single string, which will be the field’s title and field name respectively. For example:

When using the first form of dictionary-based specification, the titles may be supplied as an extra 'titles' key as described above. When using the second (discouraged) dictionary-based specification, the title can be supplied by providing a 3-element tuple (datatype, offset, title) instead of the usual 2-element tuple:

The dtype.fields dictionary will contain titles as keys, if any titles are used. This means effectively that a field with a title will be represented twice in the fields dictionary. The tuple values for these fields will also have a third element, the field title. Because of this, and because the names attribute preserves the field order while the fields attribute may not, it is recommended to iterate through the fields of a dtype using the names attribute of the dtype, which will not list titles, as in:

Union types #

Structured datatypes are implemented in numpy to have base type numpy.void by default, but it is possible to interpret other numpy types as structured types using the (base_dtype, dtype) form of dtype specification described in Data Type Objects . Here, base_dtype is the desired underlying dtype, and fields and flags will be copied from dtype . This dtype is similar to a ‘union’ in C.

Indexing and assignment to structured arrays #

Assigning data to a structured array #.

There are a number of ways to assign values to a structured array: Using python tuples, using scalar values, or using other structured arrays.

Assignment from Python Native Types (Tuples) #

The simplest way to assign values to a structured array is using python tuples. Each assigned value should be a tuple of length equal to the number of fields in the array, and not a list or array as these will trigger numpy’s broadcasting rules. The tuple’s elements are assigned to the successive fields of the array, from left to right:

Assignment from Scalars #

A scalar assigned to a structured element will be assigned to all fields. This happens when a scalar is assigned to a structured array, or when an unstructured array is assigned to a structured array:

Structured arrays can also be assigned to unstructured arrays, but only if the structured datatype has just a single field:

Assignment from other Structured Arrays #

Assignment between two structured arrays occurs as if the source elements had been converted to tuples and then assigned to the destination elements. That is, the first field of the source array is assigned to the first field of the destination array, and the second field likewise, and so on, regardless of field names. Structured arrays with a different number of fields cannot be assigned to each other. Bytes of the destination structure which are not included in any of the fields are unaffected.

Assignment involving subarrays #

When assigning to fields which are subarrays, the assigned value will first be broadcast to the shape of the subarray.

Indexing structured arrays #

Accessing individual fields #.

Individual fields of a structured array may be accessed and modified by indexing the array with the field name.

The resulting array is a view into the original array. It shares the same memory locations and writing to the view will modify the original array.

This view has the same dtype and itemsize as the indexed field, so it is typically a non-structured array, except in the case of nested structures.

If the accessed field is a subarray, the dimensions of the subarray are appended to the shape of the result:

Accessing Multiple Fields #

One can index and assign to a structured array with a multi-field index, where the index is a list of field names.

The behavior of multi-field indexes changed from Numpy 1.15 to Numpy 1.16.

The result of indexing with a multi-field index is a view into the original array, as follows:

Assignment to the view modifies the original array. The view’s fields will be in the order they were indexed. Note that unlike for single-field indexing, the dtype of the view has the same itemsize as the original array, and has fields at the same offsets as in the original array, and unindexed fields are merely missing.

In Numpy 1.15, indexing an array with a multi-field index returned a copy of the result above, but with fields packed together in memory as if passed through numpy.lib.recfunctions.repack_fields .

The new behavior as of Numpy 1.16 leads to extra “padding” bytes at the location of unindexed fields compared to 1.15. You will need to update any code which depends on the data having a “packed” layout. For instance code such as:

will need to be changed. This code has raised a FutureWarning since Numpy 1.12, and similar code has raised FutureWarning since 1.7.

In 1.16 a number of functions have been introduced in the numpy.lib.recfunctions module to help users account for this change. These are numpy.lib.recfunctions.repack_fields . numpy.lib.recfunctions.structured_to_unstructured , numpy.lib.recfunctions.unstructured_to_structured , numpy.lib.recfunctions.apply_along_fields , numpy.lib.recfunctions.assign_fields_by_name , and numpy.lib.recfunctions.require_fields .

The function numpy.lib.recfunctions.repack_fields can always be used to reproduce the old behavior, as it will return a packed copy of the structured array. The code above, for example, can be replaced with:

Furthermore, numpy now provides a new function numpy.lib.recfunctions.structured_to_unstructured which is a safer and more efficient alternative for users who wish to convert structured arrays to unstructured arrays, as the view above is often intended to do. This function allows safe conversion to an unstructured type taking into account padding, often avoids a copy, and also casts the datatypes as needed, unlike the view. Code such as:

can be made safer by replacing with:

Assignment to an array with a multi-field index modifies the original array:

This obeys the structured array assignment rules described above. For example, this means that one can swap the values of two fields using appropriate multi-field indexes:

Indexing with an Integer to get a Structured Scalar #

Indexing a single element of a structured array (with an integer index) returns a structured scalar:

Unlike other numpy scalars, structured scalars are mutable and act like views into the original array, such that modifying the scalar will modify the original array. Structured scalars also support access and assignment by field name:

Similarly to tuples, structured scalars can also be indexed with an integer:

Thus, tuples might be thought of as the native Python equivalent to numpy’s structured types, much like native python integers are the equivalent to numpy’s integer types. Structured scalars may be converted to a tuple by calling numpy.ndarray.item :

Viewing structured arrays containing objects #

In order to prevent clobbering object pointers in fields of object type, numpy currently does not allow views of structured arrays containing objects.

Structure comparison and promotion #

If the dtypes of two void structured arrays are equal, testing the equality of the arrays will result in a boolean array with the dimensions of the original arrays, with elements set to True where all fields of the corresponding structures are equal:

NumPy will promote individual field datatypes to perform the comparison. So the following is also valid (note the 'f4' dtype for the 'a' field):

To compare two structured arrays, it must be possible to promote them to a common dtype as returned by numpy.result_type and numpy.promote_types . This enforces that the number of fields, the field names, and the field titles must match precisely. When promotion is not possible, for example due to mismatching field names, NumPy will raise an error. Promotion between two structured dtypes results in a canonical dtype that ensures native byte-order for all fields:

The resulting dtype from promotion is also guaranteed to be packed, meaning that all fields are ordered contiguously and any unnecessary padding is removed:

Note that the result prints without offsets or itemsize indicating no additional padding. If a structured dtype is created with align=True ensuring that dtype.isalignedstruct is true, this property is preserved:

When promoting multiple dtypes, the result is aligned if any of the inputs is:

The < and > operators always return False when comparing void structured arrays, and arithmetic and bitwise operations are not supported.

Changed in version 1.23: Before NumPy 1.23, a warning was given and False returned when promotion to a common dtype failed. Further, promotion was much more restrictive: It would reject the mixed float/integer comparison example above.

Record arrays #

As an optional convenience numpy provides an ndarray subclass, numpy.recarray that allows access to fields of structured arrays by attribute instead of only by index. Record arrays use a special datatype, numpy.record , that allows field access by attribute on the structured scalars obtained from the array. The numpy.rec module provides functions for creating recarrays from various objects. Additional helper functions for creating and manipulating structured arrays can be found in numpy.lib.recfunctions .

The simplest way to create a record array is with numpy.rec.array :

numpy.rec.array can convert a wide variety of arguments into record arrays, including structured arrays:

The numpy.rec module provides a number of other convenience functions for creating record arrays, see record array creation routines .

A record array representation of a structured array can be obtained using the appropriate view :

For convenience, viewing an ndarray as type numpy.recarray will automatically convert to numpy.record datatype, so the dtype can be left out of the view:

To get back to a plain ndarray both the dtype and type must be reset. The following view does so, taking into account the unusual case that the recordarr was not a structured type:

Record array fields accessed by index or by attribute are returned as a record array if the field has a structured type but as a plain ndarray otherwise.

Note that if a field has the same name as an ndarray attribute, the ndarray attribute takes precedence. Such fields will be inaccessible by attribute but will still be accessible by index.

Recarray helper functions #

Collection of utilities to manipulate structured arrays.

Most of these functions were initially implemented by John Hunter for matplotlib. They have been rewritten and extended for convenience.

Add new fields to an existing array.

The names of the fields are given with the names arguments, the corresponding values with the data arguments. If a single field is appended, names , data and dtypes do not have to be lists but just values.

Input array to extend.

String or sequence of strings corresponding to the names of the new fields.

Array or sequence of arrays storing the fields to add to the base.

Datatype or sequence of datatypes. If None, the datatypes are estimated from the data .

Filling value used to pad missing data on the shorter arrays.

Whether to return a masked array or not.

Whether to return a recarray (MaskedRecords) or not.

Apply function ‘func’ as a reduction across fields of a structured array.

This is similar to numpy.apply_along_axis , but treats the fields of a structured array as an extra axis. The fields are all first cast to a common type following the type-promotion rules from numpy.result_type applied to the field’s dtypes.

Function to apply on the “field” dimension. This function must support an axis argument, like numpy.mean , numpy.sum , etc.

Structured array for which to apply func.

Result of the recution operation

Assigns values from one structured array to another by field name.

Normally in numpy >= 1.14, assignment of one structured array to another copies fields “by position”, meaning that the first field from the src is copied to the first field of the dst, and so on, regardless of field name.

This function instead copies “by field name”, such that fields in the dst are assigned from the identically named field in the src. This applies recursively for nested structures. This is how structure assignment worked in numpy >= 1.6 to <= 1.13.

The source and destination arrays during assignment.

If True, fields in the dst for which there was no matching field in the src are filled with the value 0 (zero). This was the behavior of numpy <= 1.13. If False, those fields are not modified.

Return a new array with fields in drop_names dropped.

Nested fields are supported.

Changed in version 1.18.0: drop_fields returns an array with 0 fields if all fields are dropped, rather than returning None as it did previously.

Input array

String or sequence of strings corresponding to the names of the fields to drop.

Whether to return a recarray or a mrecarray ( asrecarray=True ) or a plain ndarray or masked array with flexible dtype. The default is False.

Find the duplicates in a structured array along a given key

Name of the fields along which to check the duplicates. If None, the search is performed by records

Whether masked data should be discarded or considered as duplicates.

Whether to return the indices of the duplicated values.

Flatten a structured data-type description.

Returns a dictionary with fields indexing lists of their parent fields.

This function is used to simplify access to fields nested in other fields.

Input datatype

Last processed field name (used internally during recursion).

Dictionary of parent fields (used interbally during recursion).

Returns the field names of the input datatype as a tuple. Input datatype must have fields otherwise error is raised.

Returns the field names of the input datatype as a tuple. Input datatype must have fields otherwise error is raised. Nested structure are flattened beforehand.

Join arrays r1 and r2 on key key .

The key should be either a string or a sequence of string corresponding to the fields used to join the array. An exception is raised if the key field cannot be found in the two input arrays. Neither r1 nor r2 should have any duplicates along key : the presence of duplicates will make the output quite unreliable. Note that duplicates are not looked for by the algorithm.

A string or a sequence of strings corresponding to the fields used for comparison.

Structured arrays.

If ‘inner’, returns the elements common to both r1 and r2. If ‘outer’, returns the common elements as well as the elements of r1 not in r2 and the elements of not in r2. If ‘leftouter’, returns the common elements and the elements of r1 not in r2.

String appended to the names of the fields of r1 that are present in r2 but absent of the key.

String appended to the names of the fields of r2 that are present in r1 but absent of the key.

Dictionary mapping field names to the corresponding default values.

Whether to return a MaskedArray (or MaskedRecords is asrecarray==True ) or a ndarray.

Whether to return a recarray (or MaskedRecords if usemask==True ) or just a flexible-type ndarray.

The output is sorted along the key.

A temporary array is formed by dropping the fields not in the key for the two arrays and concatenating the result. This array is then sorted, and the common entries selected. The output is constructed by filling the fields with the selected entries. Matching is not preserved if there are some duplicates…

Merge arrays field by field.

Sequence of arrays

Whether to collapse nested fields.

Without a mask, the missing value will be filled with something, depending on what its corresponding type:

-1 for integers

-1.0 for floating point numbers

'-' for characters

'-1' for strings

True for boolean values

XXX: I just obtained these values empirically

Returns a new numpy.recarray with fields in drop_names dropped.

Join arrays r1 and r2 on keys. Alternative to join_by, that always returns a np.recarray.

equivalent function

Fills fields from output with fields from input, with support for nested structures.

Input array.

Output array.

output should be at least the same size as input

Rename the fields from a flexible-datatype ndarray or recarray.

Input array whose fields must be modified.

Dictionary mapping old field names to their new version.

Re-pack the fields of a structured array or dtype in memory.

The memory layout of structured datatypes allows fields at arbitrary byte offsets. This means the fields can be separated by padding bytes, their offsets can be non-monotonically increasing, and they can overlap.

This method removes any overlaps and reorders the fields in memory so they have increasing byte offsets, and adds or removes padding bytes depending on the align option, which behaves like the align option to numpy.dtype .

If align=False , this method produces a “packed” memory layout in which each field starts at the byte the previous field ended, and any padding bytes are removed.

If align=True , this methods produces an “aligned” memory layout in which each field’s offset is a multiple of its alignment, and the total itemsize is a multiple of the largest alignment, by adding padding bytes as needed.

array or dtype for which to repack the fields.

If true, use an “aligned” memory layout, otherwise use a “packed” layout.

If True, also repack nested structures.

Copy of a with fields repacked, or a itself if no repacking was needed.

Casts a structured array to a new dtype using assignment by field-name.

This function assigns from the old to the new array by name, so the value of a field in the output array is the value of the field with the same name in the source array. This has the effect of creating a new ndarray containing only the fields “required” by the required_dtype.

If a field name in the required_dtype does not exist in the input array, that field is created and set to 0 in the output array.

array to cast

datatype for output array

array with the new dtype, with field values copied from the fields in the input array with the same name

Superposes arrays fields by fields

Sequence of input arrays.

Whether automatically cast the type of the field to the maximum.

Converts an n-D structured array into an (n+1)-D unstructured array.

The new array will have a new last dimension equal in size to the number of field-elements of the input array. If not supplied, the output datatype is determined from the numpy type promotion rules applied to all the field datatypes.

Nested fields, as well as each element of any subarray fields, all count as a single field-elements.

Structured array or dtype to convert. Cannot contain object datatype.

The dtype of the output unstructured array.

If true, always return a copy. If false, a view is returned if possible, such as when the dtype and strides of the fields are suitable and the array subtype is one of numpy.ndarray , numpy.recarray or numpy.memmap .

Changed in version 1.25.0: A view can now be returned if the fields are separated by a uniform stride.

See casting argument of numpy.ndarray.astype . Controls what kind of data casting may occur.

Unstructured array with one more dimension.

Converts an n-D unstructured array into an (n-1)-D structured array.

The last dimension of the input array is converted into a structure, with number of field-elements equal to the size of the last dimension of the input array. By default all output fields have the input array’s dtype, but an output structured dtype with an equal number of fields-elements can be supplied instead.

Nested fields, as well as each element of any subarray fields, all count towards the number of field-elements.

Unstructured array or dtype to convert.

The structured dtype of the output array

If dtype is not supplied, this specifies the field names for the output dtype, in order. The field dtypes will be the same as the input array.

Whether to create an aligned memory layout.

See copy argument to numpy.ndarray.astype . If true, always return a copy. If false, and dtype requirements are satisfied, a view is returned.

Structured array with fewer dimensions.

Get the Reddit app

The subreddit for the C programming language

assignment makes integer from pointer without a cast

I'm trying to parse network packets in C as:

ip_hdr_t is a struct defines the IP header and it has a member uint8_t ihl:4 .

When compiling the code it gave warnings and errors:

I understand the first warning, but how did the second one in line 60 come? ip_hdr is uint8_t* and ip_hdr_len is uint8_t , so I expect the addition produces an uint8_t* instead of an integer ?

By continuing, you agree to our User Agreement and acknowledge that you understand the Privacy Policy .

Enter the 6-digit code from your authenticator app

You’ve set up two-factor authentication for this account.

Enter a 6-digit backup code

Create your username and password.

Reddit is anonymous, so your username is what you’ll go by here. Choose wisely—because once you get a name, you can’t change it.

Reset your password

Enter your email address or username and we’ll send you a link to reset your password

Check your inbox

An email with a link to reset your password was sent to the email address associated with your account

Choose a Reddit account to continue

IMAGES

  1. assignment makes integer from pointer without a cast

    assignment makes integer from pointer without a cast meaning

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

    assignment makes integer from pointer without a cast meaning

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

    assignment makes integer from pointer without a cast meaning

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

    assignment makes integer from pointer without a cast meaning

  5. Solved error: assignment makes pointer from integer without

    assignment makes integer from pointer without a cast meaning

  6. Comparison Between Pointer And Integer

    assignment makes integer from pointer without a cast meaning

COMMENTS

  1. What does "assignment makes pointer from integer without a cast" mean?

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

  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. Assignment makes integer from pointer without a cast in c

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

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

  5. Assignment Makes Integer From Pointer Without A Cast In C (Resolved)

    When I declare a char * to a fixed string and reuse the pointer to point to another string /* initial declaration */char *src = "abcdefghijklmnop";.....

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

  7. Need help with C, keep getting "assignment makes pointer from integer

    char *word is a pointer, meaning the value contained by the word parameter is a memory address (in this example, it will be the address of the first character in a string). When you use the notation *word on line 19, you are dereferencing the word pointer, meaning it will return the value of whatever is stored at word's memory address (which is a single character).

  8. 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 avoided.

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

  10. Assignment makes pointer from integer without a cast

    You are trying to convert an pointer to an integer without cast and it is simply telling you that the correct type is what pS type is that is the thing that line is trying to set after all. pS = (const char *) (pS0+n) That all said it would be a hell of a lot easier to make PS0 a const char* and simply tell it. pS= (const char *)&pS0 [n];

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

  12. [Warning]assignment makes integer from pointer without a cast

    warning: assignment makes pointer from integer without a cast I get that when I compile a C file where the function is defined as this: char **getvars () and the calling function has this declared: char **s; and I write: s=getvars (); C / C++. 1. 3853. warning assignment makes integer from pointer without a cast.

  13. How to fix "warning: assignment to 'int (*)(int, int, int, void

    How to fix "warning: assignment to 'int (*)(int, int, int, void *)' from 'int' makes pointer from integer without a cast [-Wint-conversion]" I am currently reading a book on Ethical Hacking and I have hit a road block with this warning. The book uses C for this example in Sys call hooking, and I seem to keep getting this warning message ...

  14. 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. 2. Objective_Ad_4587 • 3 yr. ago. i got it thank you very much.

  15. What is assignment makes pointer from integer without a cast

    Code: Select all. kernel.c: In function 'kbdhandler': kernel.c:199:6: warning: assignment makes pointer from integer without a cast [enabled by default] key = kbdus[scancode]; ^. This is to set the key to the translated scancode-key result. Here's my kbdus and kbdhandler function, inb and terminal_writestring are exactly as shown in the OSDev ...

  16. Assignment makes integer from pointer without a cast and program

    OK - in that case, since you want to immediately change the value of sad, it can be a local variable to the function, and doesn't need to be an argument to the function: . void racun(int D, int M, int G, int *dUg) { int i, *sad; If you want sad to point to an array, such that accessing sad (sad[...]) will be equivalent to accessing that array (e.g. obicna[...]), you can simply assign the array ...

  17. c

    When the executable image is generated from your code, the string is placed in the code-section, which is one of several memory-sections within the program. The compiler then replaces the so-called "string assignment" with a so-called "integer assignment". For example, char* x = "abc" is changed into char* x = (char*)0x82004000 before being ...

  18. Structured arrays

    The fields are all first cast to a common type following the type-promotion rules from numpy.result_type applied to the field's dtypes. Parameters: func function. Function to apply on the "field" dimension. This function must support an axis argument, like numpy.mean, numpy.sum, etc. arr ndarray. Structured array for which to apply func ...

  19. assignment makes integer from pointer without a cast [enabled by

    This is my last program, and I have done quite well with the other 15. Errors: |43|warning: assignment makes integer from pointer without a cast [enabled by default]| |44|warning: assignment makes integer from pointer without a cast [enabled by default]| |46|error: incompatible types when assigning to type 'int [100]' from type 'int *'| |47 ...

  20. assignment makes integer from pointer without a cast

    ip_hdr_t is a struct defines the IP header and it has a member uint8_t ihl:4 . 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]