Ubuntu Forums

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

Ubuntu Forums Code of Conduct

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

Home

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

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

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

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

usernamer is offline

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

r-senior is offline

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

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

Christmas is offline

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

Tags for this Thread

View Tag Cloud

Posting Permissions

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

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,256 software developers and data experts.

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

ERROR: 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: ERROR: assignment makes integer from pointer without a cast

Thread tools.

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

ehitam is offline

Code: char *mid(char *tString, int x1, int x2){ char *rString; int i, l; rString= (char *) malloc(sizeof(char) * x2); l = x1-1; for (i= 0; i<x2; i++) { rString[i] = tString[l]; l++; } rString[x2]= NULL; return rString; } Mingw is giving me this error: C:\Users\Harshvardhan\Desktop\RPL\functions.h|30|w arning: assignment makes integer from pointer without a cast [enabled by default]| and for this line: Code: rString[x2]= NULL; And possible reason/cure for this?

anduril462 is offline

rString is a pointer (presumably to an array of chars or a string). Therefore rString[x2] is a single char. But NULL is a pointer type, which is not compatible with char. You are probably looking for the null byte/character (yes, slightly confusing) to terminate your string. Try Code: rString[x2] = '\0';
  • Visit Homepage

laserlight is offline

NULL is a null pointer constant. While it could just be the integer 0, it could also be (void*)0 or something else that ultimately is a null pointer constant. What you really want is a character constant, so just write: Code: rString[x2] = '\0'; By the way, as a single letter name, l is a horrible name as it can be confused with 1 on some fonts.
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
lol... And I always thought that NULL is exactly same as '\0'
Originally Posted by ehitam I always thought that NULL is exactly same as '\0' On some implementations, it is. Except for spelling, 0 is identical to '\0'. But you should not rely on that.
Originally Posted by laserlight By the way, as a single letter name, l is a horrible name as it can be confused with 1 on some fonts. I agree... I used it to signify length... And in code::blocks it is same as 1. I think I should change it with something better. And... Thanks laserlight and anduril for help...

stahta01 is offline

Originally Posted by laserlight NULL is a null pointer constant. While it could just be the integer 0, it could also be (void*)0 or something else that ultimately is a null pointer constant. What you really want is a character constant, so just write: Code: rString[x2] = '\0'; By the way, as a single letter name, l is a horrible name as it can be confused with 1 on some fonts. Is this a past end of array? In other words, is the code below correct? Code: rString[x2-1] = '\0'; Really tired, so my thinking might be wrong. Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
It looks more likely that the malloc should have allocated another char.
Originally Posted by stahta01 Is this a past end of array? No... x2-1 just make a character less... x2 is fine.
Originally Posted by laserlight It looks more likely that the malloc should have allocated another char. Do you mean rString?
Originally Posted by ehitam x2 is fine. The problem is that stahta01 is correct to say that it is a problem: you're writing to the array out of bounds. If you want to do this, your malloc should have a +1.
Originally Posted by laserlight The problem is that stahta01 is correct to say that it is a problem: you're writing to the array out of bounds. If you want to do this, your malloc should have a +1. Sorry... ... I'm not getting what you mean to say... When I use x2-1.... I get a character less...
Yes, you get a character less, but it's better than undefined behavior (what array out of bounds accesses result in). Arrays in C start at index 0 and go to index SIZE-1, or in your case x2-1. That is, your current code allocates an array of x2 characters, meaning you have rString[0]...rString[x2-1]. That's it, no more. rString[x2] is out of bounds. Tim's code corrects that in one possible way (by stopping at x2-1). Laserlight suggested another way, which allocates x2+1 characters, so rString[x2] is valid.
I mean that instead of this: Code: rString= (char *) malloc(sizeof(char) * x2); you should write: Code: rString = malloc(sizeof(*rString) * x2 + 1); Notice the +1 to account for the null character.
oh! Really didn't noticed that Thank you for help... I would replace x2 with x2+1

Next

  • 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

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

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

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.

C语言Warning:assignment to ‘int‘ from ‘int*‘ makes integer from pointer without a cast引发的思考

error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

1 这个警告是什么意思?

2.1 引起问题的错误理解    , 2.2 警告出现的原因与解决方案探索.

    适逢研0假期,研究生导师暂未安排任务,鄙人自学之余,想起本科恩师叮咛:“嵌入式的能力不能丢。”,遂将嵌入式C语言也纳入自学范围之中,重新打基础。一日见网课老师程序示例,如下图所示。

error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

     于是临时起兴,在VSCode中进行指针的初级实验,敲入如下代码

    自信满满点击运行,结果喜提Warning:assignment to 'int' from 'int*' makes integer from pointer without a cast。输出结果则如下所示。

the *p is 5ffe94. the p is 1b5d90. the *p is 12345678. the p is 5ffe94.

    自行琢磨一会儿自觉没什么问题(鄙人粗陋基础可见一斑),遂请教高人,得启发,将此次所得进行记录。

    意思是我们将int类型的值赋给了一个int*类型的变量。

    按图索骥,重新回看代码——不对啊,我明明加了强制类型转换不是吗?而且视频里老师也是这么写的,也没有报Warning呀?

    对比老师的示例代码,发现老师是在初始化指针变量的时候对其进行了赋值,于是我修改了代码,尝试也在初始化指针变量的时候对其进行赋值,如下所示。

    再看输出结果,很好,符合预期。

the *p is 12345678. the p is 5ffe94. the *p is 12345678. the p is 5ffe94.

    结合高人所述,当我们初始化指针变量时写的这句int *p实际上是定义了一个int*类型的变量p,更好理解就是(int*) p而不是int (*p)。

    在初始化时也应该认为是(int*) p = &a,而不是int (*p = &a)。

    即初始化的这一句,

    其效果等价于我们写了以下这两句。

    我们错误代码的输出到底代表了什么呢?

    先看第一行,输出的是变量a存储的内存地址,这是不需要过多解释的,因为我们确实使指针指向的地址中存放了a的地址。但这也是导致警告出现的原因, *p指向的数据是int类型,而&a返回的是int*类型 ,这是不匹配的。

the *p is 5ffe94.

    于是我想,那我强制类型转换成int类型不就完了,遂修改代码如下。

    结果是,喜提新的Warning:cast to pointer from integer of different size。就是说赋的值和指针具有不同的大小,我们可以用sizeof看看*p和&a的大小,再进一步选择强制类型转换的类型。

    得到的结果如下所示。

the length of *p is 4. the length of &a is 8.

    这意味着如果我们要实现把a的地址存放在内存中并能通过指针正常访问的功能,我们应当让计算机以8字节/单位去访问内存,而非我们定义的int *p(即以4字节/单位去访问内存)。那就得在定义指针变量时就进行修改——嚯!坑越挖越大!

    于是再修改代码,long long int类型的变量正是8字节的,于是定义一个long long int*类型的指针,让计算机以8个字节/单位去访问内存。

    这下得到的输出如下图所示,编译器也没有报错了。

the length of *p is 8. the length of &a is 8. the *p is 5ffe94. the p is 1d5d90.

    在2.1中,第二行输出的是一个不知道怎么来的地址,而且多次编译,运行后得到的还不一样!如下图所示是连续两次编译得到的输出结果,可以看到第一次输出的是9e5d90,第二次则是195d90。

error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

    多编译几次,还能得到更多不同的输出结果,有时会相同,但奇怪的是他们末尾都是‘5d90’。

    这是因为如果我们没有在初始化时指定指针指向的地址,系统就会让其指向一段随机内存,这段内存是什么形式的(可读?可写?不可访问?合法的?非法的?)我们是不知道的,这就可能引起严重的问题,这种问题就是我们常说的“野指针”问题。

    这下对C语言指针的理解更深了!如文章内容有不妥或鄙人有理解错误的地方,还请路过的大佬不吝赐教!继续学习,继续热爱!

error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

“相关推荐”对你有帮助么?

error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

请填写红包祝福语或标题

error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。 2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

IMAGES

  1. Array : warning: assignment makes pointer from integer without a cast

    error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

  2. [Solved] Error: initialization makes pointer from integer

    error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

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

    error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

  4. assignment makes pointer from integer without a cast(C语言头文件)-CSDN博客

    error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

  5. [Solved]-initialization makes integer from pointer without a cast

    error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

  6. "assignment makes integer from pointer without a cast -wint-conversion

    error assignment to ‘int’ from ‘int *’ makes integer from pointer without a cast

VIDEO

  1. INT makes Phins fan speechless🤢 #nfl #playoffs #sports

  2. Variables in C++

  3. OWASP API Security Top 10

  4. Teardown

  5. Madden 24 End it in the 1st

  6. Embedded System Roadmap

COMMENTS

  1. c error: assignment makes integer from pointer without a cast [-Werror

    Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.Provide details and share your research! But avoid …. Asking for help, clarification, or responding to other answers.

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

    Instead, you need to use functions like strncpy and friends from <string.h> and use char arrays instead of char pointers. If you merely want the pointer to point to a different static string, then drop the *. The warning comes from the fact that you're dereferencing src in the assignment.

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

    We are trying here to assign the return of getinteger function which is a pointer that conatains a memory address to the result variable that is an int type which needs an integer Case 3: Misusing ...

  4. [SOLVED] C

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

  5. assignment to 'int *' from 'int' ... : r/cprogramming

    assignment to 'int *' from 'int' makes pointer from integer without a cast. What am i missing? You are allocating and using an array of pointers-to-integer (int** gpio is a pointer to a pointer to an int). You probably want to use a normal array here (int* gpio), but you won't be able to NULL terminate it like you're trying to do now.

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

    The warning is telling you that you're storing an int in a variable that expects a int (*)(int, int, int, void*). So you could get rid of the warning by, instead of casting to int , casting to int (*)(int, int, int, void*) , which effectively tells the compiler "don't worry, I know what I'm doing with this pointer" :

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

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

    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: A character string literal has static storage duration and type "array of char", and is initialized with the given characters. A wide string literal has static storage duration and type "array of wchar_t", and is initialized with the wide characters corresponding to ...

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

  10. c

    Firstly, char *main() is illegal in C. It should be int main().. Secondly, 'a' and the like are integer constants in C. You cannot use them to initialize and array of char * elements. If you wanted a char array you should have declared it as. const char vowels[] = {'a', 'e', 'i', 'o', 'u'}; If you wanted a string array you should have declared it as

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

    The following code in c+ gives me the warning assignment makes integer from pointer without a cast. destination is set as char destination to limit the input string to 10 characters. name is an... C / C++. 3. Access Europe Meeting - Wed 3 Jan.

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

    While it could just be the integer 0, it could also be (void*)0 or something else that ultimately is a null pointer constant. What you really want is a character constant, so just write: Code:

  13. C error

    n.c:43:18: warning: assignment makes integer from pointer without a cast [enabled by default] firstInitial = "M"; ^ n.c:44:19: warning: assignment makes integer from pointer without a cast [enabled by default] secondInitial = "T"; ^

  14. compiler warning: pointer from integer without a cast

    and the following warnings: passing argument 2 of 'sd_ppi_channel_assign' makes pointer from integer without a cast [-Wint-conversion] passing argument 3 of 'sd_ppi_channel_assign' makes pointer from integer without a cast [-Wint-conversion] All seems to work, but would appreciate understanding the warnings. Many thanks,

  15. c

    2 Answers. NO. They are not. They both are arrays, but the datatype is different. One is a uint8_t * array, another is a uint8_t array. uint8_t *tmp[8]; It wasn't my downvote, but I don't see where his code uses a pointer from tmp uninitialized. He's assigning to the i th item of tmp, not dereferencing it.

  16. 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. #include <stdint.h>.

  17. assignment makes integer from pointer without a cast

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

  18. C语言Warning:assignment to 'int' from 'int*' makes integer from pointer

    近日遇见一个bug,最后调查是程序的warning引起的: 编译的时候报警告: assignment makes pointer from integer without a cast 出现这个警告的原因是在使用函数之前没有对函数进行声明,未经声明的函数原型一律默认为返回int值。就相当于你调用了返回值为int的函数,并将其赋给了char*变量,所有会出现警告。

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

  20. assignment to 'char *' from 'int' makes pointer from integer without a

    Otherwise, the compiler will assume it returns an int, and complain when you want to assign the value to a variable of type char * . rjcarr. If you're new to C then why are you trying to use variadic functions, ha? Not completely sure, but on this line: p = itoa (num); You probably want: p = itoa (*num); Since otherwise you're sending a pointer ...