c - 警告 : pointer targets in initialization differ in signedness

我的编译器 (gcc) 显示警告

警告:初始化中的指针目标的符号不同

请帮我看看为什么会出现这个警告。

字符串文字不是 unsigned char* 类型。

您可能打算在您的结构中键入 const char* 。如果不是,您可能不希望在不使其成为 const 的情况下为其分配字符串文字,因为修改字符串文字所在的内存是非法的。

关于c - 警告 : pointer targets in initialization differ in signedness,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8441368/

上一篇: c - 当我在 malloc 中取消引用 NULL 指针时,为什么我的程序没有出现段错误?

下一篇: c - c中的静态变量.

c - Android 4.4,对 __printf_chk 的 undefined reference

c - 仅将负数相乘并仅从 C 中的文件中输出负整数

c - 多文件直接编译ok,直接编译报错

c - 结构数组内存排列

c - 查找c头文件中的所有宏定义

c - 在两个头文件中使用特殊类型时出现问题。 (C代码)

c - pop & push 减法和除法

c - printf 和 scanf 的逻辑问题

c - 删除双向链表中的元素时遇到问题

c - 如何在 Linux 中设置文件时间戳?

©2024 IT工具网   联系我们

  • | New Account
  • | Log In Remember [x]
  • | Forgot Password Login: [x]
  • Format For Printing
  •  -  XML
  •  -  Clone This Bug
  •  -  Top of page

warning: pointer targets in assignment differ in signedness

  • Re: warning: pointer targets in assignment differ in signedness , Pawel Kot , 2006/01/05
  • Prev by Date: menu AT Command
  • Next by Date: Re: warning: pointer targets in assignment differ in signedness
  • Previous by thread: menu AT Command
  • Next by thread: Re: warning: pointer targets in assignment differ in signedness

Join us to learn how we are empowering innovation from our expert embedded design engineers. Classes are open to all skill levels and cover an array of embedded control topics. Secure your spot now and stay ahead of the curve at MASTERs 2024 .

  • Menu About Community Forums

pointer targets in assignment differ in signedness

  • STMicroelectronics Community
  • STM32 MCUs products
  • Warning: pointer targets in passing argument 2 of ...
  • Subscribe to RSS Feed
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Printer Friendly Page

Warning: pointer targets in passing argument 2 of 'HAL_UART_Receive' differ in signedness [-Wpointer-sign]

MKork.2

  • Mark as New
  • Email to a Friend
  • Report Inappropriate Content

‎2022-06-28 06:19 PM

Solved! Go to Solution.

  • All forum topics
  • Previous Topic

Andrew Neil

‎2022-06-29 01:26 AM

View solution in original post

waclawek.jan

‎2022-06-28 11:05 PM

‎2022-06-29 12:48 AM

Nikita91

‎2022-06-29 01:28 AM

‎2022-06-29 01:42 AM

‎2022-06-29 04:52 AM

‎2022-06-29 05:16 AM

‎2022-06-29 06:40 AM

‎2022-06-29 07:11 AM

0693W000008y9fZQAQ.png

  • FreeRTOS acquisition and release? in STM32 MCUs Embedded software 2024-05-22
  • Simple UART problem STM32H753 in STM32 MCUs products 2024-05-22
  • stm32 with simcom A7672S in STM32CubeIDE (MCUs) 2024-05-20
  • regarding issues in Stm32lo51 with simcom a7670c in STM32CubeIDE (MCUs) 2024-05-20
  • Connecting stm32F7 Disco board to WIFI network using esp8266 in STM32 MCUs Wireless 2024-05-20

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pointer targets in initialization differ in signedness #223

@githubaf

githubaf commented Jun 17, 2021

@bebbo

bebbo commented Jun 17, 2021

Sorry, something went wrong.

githubaf commented Jun 23, 2021

@githubaf

bebbo commented Jun 23, 2021

No branches or pull requests

@bebbo

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Anbu

pointer targets in passing argument 1 of 'strlen' differ in signedness

Posted on Apr 6, 2007 4:12 AM

etresoft

Posted on Apr 6, 2007 7:16 AM

Loading page content

Page content loaded

There are no replies.

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.

c - 如何避免普通“char”到:“unsigned char”或“signed char”转换的gcc警告?

我的默认字符类型是 gcc 选项 (-funsigned-char gcc) 中设置的“无符号字符”。所以可以说,当我在代码中需要“unsigned char”时,我可以使用“char”。但是我收到了关于 (char*) 和 (unsigned char* 或 signed char*) 之间转换的警告:

"error: pointer targets in passing argument 1 of 'test2' differ in signedness" .

当我将 unsigned char* 变量传递给 char* 时,如何避免警告(知道我的系统具有编译器选项设置的默认 unsigned char)?

开关 -funsigned-char 并 -fsigned-char 没有参考 char * 。

您可以使用 -Wno-pointer-sign 来关闭收到的警告。

正确的解决方案是将正确类型的变量传递给函数,即如果函数需要纯字符,则声明纯字符并获取其地址,依此类推。

C 标准规定“char”、“signed char”和“unsigned char”是不同的类型。"char" 必须具有与 "signed char" 或 "unsigned char" 相同的行为,由编译器开关确定,但您不能互换使用它们。无论您是否使用 -funsigned-char,您都应该编写完全相同的代码。

另一张海报使用演员表的建议并不好。所做的只是抑制警告,明确禁用警告会更清楚(例如,使用编译指示,或在您的生成文件中全局关闭警告)。

演员表并没有解决代码的问题,它只是阻止编译器指出它。这是一个有点学术的观点,但在非 2 的补码系统上,带符号的字符可能有陷阱表示(它们与值 0 <= x <= CHAR_MAX 但不是其他值的布局兼容)。所以代码可能会崩溃。

根据您提供的详细信息,实际上您的最佳解决方案可能只是禁用警告并接受代码在这方面不可移植的事实。

所有 char 类型都是布局兼容的,并且转换它们的指针不构成类型双关语或违反别名规则,因此您可以自由地这样做。

-Wpointer-sign 由 -Wall 和 -pedantic 暗示。为了避免警告使用 -Wno-pointer-sign

IMAGES

  1. Pointer Expressions in C with Examples

    pointer targets in assignment differ in signedness

  2. Pointer Expressions in C with Examples

    pointer targets in assignment differ in signedness

  3. Pointer Expressions in C with Examples

    pointer targets in assignment differ in signedness

  4. Pointer Expressions in C with Examples

    pointer targets in assignment differ in signedness

  5. Pointer Expressions in C with Examples

    pointer targets in assignment differ in signedness

  6. PPT

    pointer targets in assignment differ in signedness

VIDEO

  1. Segment Anything from Meta: strong points and limitations

  2. Stay tuned for t2.fi 2024

  3. 20240204 CISP 310 (kind of applicable to CISP 440, too) how to read Tak's modules (and signedness)

  4. What are Pointers? How to Use Them? and How they can Improve your C++ Programming Skills

  5. 2. Declaring & Initializing Pointers in C++

  6. The 147 Pointer!!! Wait for the end! 🤯 #trickshot #dudeperfect #espn

COMMENTS

  1. warning: pointer targets in initialization differ in signedness

    You may get the same warning ("pointer targets in passing argument 1 of 'Display' differ in signedness"). This warning is due the flag -Wpointer-sign that, quoting GNU compiler reference, " ...is implied by -Wall and by -pedantic, which can be disabled with -Wno-pointer-sign ". edited Jun 13, 2015 at 22:06. Mateusz Piotrowski.

  2. Pointer targets in passing argument differ in signedness

    11. char is signed type. uint8_t is unsigned. So you are passing a pointer to an unsigned type to a function requiring signed. You have several options: 1) Change the function signature to accept uint8_t* instead of char*. 2) Change the type of parameter you are passing to char* instead of uint8_t* (i.e. change data to be char ).

  3. pointer targets in assignment differ in s…

    pointer targets in assignment differ in signedness. Just to make sure I'm not going to run into anything "quirky".... Compiling the following code in a test app... unsigned char *dataPtr = NULL; send_str = "\037"; // control-/. ...generates the following warning in Xcode... PSession.m:608: warning: pointer targets in assignment differ in ...

  4. c

    最佳答案. 字符串文字不是 unsigned char* 类型。. 您可能打算在您的结构中键入 const char* 。. 如果不是,您可能不希望在不使其成为 const 的情况下为其分配字符串文字,因为修改字符串文字所在的内存是非法的。. 关于c - 警告 : pointer targets in initialization differ in ...

  5. 23087

    A user reports a misleading warning from GCC 4.0.0 when initializing pointers to signed or unsigned char with string literals. The warning should be "initialization from incompatible pointer type", not "... differ in signedness".

  6. warning: assignment discards qualifiers from pointer target type

    warning: pointer targets in assignment differ in signedness I output of the ADC is signed fractional. I tried declaring wtih both unsigned and signed and it will not allow it. as well as changing the ADC output format to just fractional...and it still dosent work.

  7. warning: pointer targets in assignment differ in signedness

    warning: pointer targets in assignment differ in signedness. Date: Tue, 3 Jan 2006 12:25:56 -0700. Repeated in various forms about 400 times. There appears to have been a universal conversion of many char * types to unsigned char * but the standard C string libraries still expect char *'s and my compiler is issuing the above warnings as a result.

  8. Error pointer targets in assignment differ in signedness #60

    mqtt/utils.c:100:12: error: pointer targets in assignment differ in signedness [-Werror=pointer-sign] start = str; cc1.exe: all warnings being treated as errors

  9. warning: pointer targets in initialization differ in signedness

    Here is the relevant code (from the MCHP TCP/IP stack): Hi matthiaswatkins, C30 3.00 emits a warning for the initialization because string constants are plain char rather than unsigned char (and plain char is a distinct type from signed char and unsigned char). The applications team responsible for the TCP/IP stack is aware of the issue.

  10. Pointer targets in initilization differ in signedness

    Thus the compiler warn your - you convert an signed char* pointer into unsigned char* pointer, they only differ in signedness. Possible fixes: Move to char. As activity_output is an array of strings (ie. char[] ), one would expect it to have a char*[] type, ie. array of pointers to strings. Your intention would be clear then.

  11. Warning: pointer targets in initialization differ in signedness?

    Warning: pointer targets in initialization differ in signedness? Warning: pointer targets in initialization differ in signedness? Go To Last Comment. Posted By: BasePointer. on 28 Apr 2009 - 03:08 PM. Posted: 28 Apr 2009 - 03:08 PM. Last Comment Date: 28 Apr 2009 - 05:06 PM. Views: 6752.

  12. pointer targets in passing argument 1 of …

    main.c:210: warning: pointer targets in passing argument 1 of 'strlen' differ in signedness main.c:212: warning: pointer targets in assignment differ in signedness main.c:213: warning: pointer targets in passing argument 1 of 'strlen' differ in signedness main.c:214: warning: pointer targets in passing argument 1 of 'strlen' differ in signedness

  13. error: pointer targets in passing argument 2 of 'getgroups' differ in

    The configure code should probably just be modified to assume that GETGROUPS_T is gid_t when cross compiling, as the code can't check the target system. Note that older rsync versions didn't fail to compile only because -pedantic-errors wasn't in effect in earlier versions, so such a type mismatch was probably just warned about but (scarily ...

  14. Solved: Warning: pointer targets in passing argument 2 of

    Look at the declaration of the HAL_UART_Receive() function. You will see that this argument asks for a pointer to uint8_t and not a pointer to char. It seems that you are new to STM, but also to the C language. Start with a C training will be very profitable.

  15. pointer targets in initialization differ in signedness #223

    return 0; } The compiler complains about "pointer targets in initialization differ in signedness". For instance OpenLibrary () expects the Libname as STRPTR. I could always cast, but that cannot be the correct way!? What could be done here instead of just supressing the warning at all with [-Wno-pointer-sign]?

  16. pointer targets in passing argument 1 of …

    main.c:212: warning: pointer targets in assignment differ in signedness main.c:213: warning: pointer targets in passing argument 1 of 'strlen' differ in signedness main.c:214: warning: pointer targets in passing argument 1 of 'strlen' differ in signedness main.c: In function 'Java JNIWrappergetWord': main.c:513: warning: return makes pointer ...

  17. c

    3. 我的默认字符类型是 gcc 选项 (-funsigned-char gcc) 中设置的"无符号字符"。. 所以可以说,当我在代码中需要"unsigned char"时,我可以使用"char"。. 但是我收到了关于 (char*) 和 (unsigned char* 或 signed char*) 之间转换的警告:. "error: pointer targets in passing argument 1 of ...

  18. pointer targets in passing argument of xxx differ in signedness

    While non-pointer int and unsigned int. From C standard c99 6.3.1.3. When a value with integer type is converted to another integer type other than _Bool, if the value can be represented by the new type, it is unchanged.

  19. 【gcc编译遇到问题】pointer targets in passing argument n of xxx differ in

    问题: pointer targets in passing argument 1 of 'strlen' differ in signedness 传递参数 1 "strlen"中的指针目标的符号不同 原因: 一般是形参与实参的参数类型不匹配。解决: 修改实参、或者形参类型,使两者保持一致。 将实参类型强制类型转换成形参类型,可消除警告。

  20. pointer targets in passing argument n of xxx differ in signedness

    问题: pointer targets in passing argument 1 of 'strlen' differ in signedness 传递参数 1 "strlen"中的指针目标的符号不同 原因: 一般是形参与实参的参数类型不匹配。 解决: 修改实参、或者形参类型,使两者保持一致。 将实参类型强制类型转换成形参类型,可消除警告。