95910 Write: const char *str; str = Inet_ntop(...); //returns const char * The function returns type 'const char*' for a reason. It's telling you "You can look, but don't touch the target of the returned pointer." HTH, -Mike Write: const char *str; str = Inet_ntop(...); //returns const char * The function returns type 'const char*' for a reason. It's telling you "You can look, but don't touch the target of the returned pointer." If you ignore this warning, you're on your own. HTH, -Mike You should declare str variable to be the same type as that being returned by Inet_ntop(). const char *str = Inet_ntop(/* ... */); The "const" is a qualifier. It means the return value of Inet_ntop is a pointer to data that should not be modified. However, in the erroneous code, you assigned that pointer to a regular "char *", which discards the "should not be modified" qualifier. -- James It can get confusing. :-) /* (0) */ int * pi; /* pointer to int */ /* (can modify p or *p) */ /* (1) */ int const * pci; /* pointer to const int */ /* (can modify p, but not *p) */ /* (2) */ const int * pci2; /* same as (1) */ /* (3) */ int * const cpi; /* const pointer to int */ /* (can modify *p, but not p */ /* (4) */ int const * const cpci; /* const pointer to const int */ /* (cannot modify p nor *p) */ /* (5) */ const int * const cpci2; /* same as (4) */ HTH, -Mike Dang, that's what I get for 'copy-n-pasting' :-) Of course the 'p' and '*p' in the comments refer to the actual identifier in each declaration ('pci', 'cpi', etc.) Sorry about that. -Mike | | | | | | | | | | | | 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. Navigation MenuSearch code, repositories, users, issues, pull requests..., provide feedback. We read every piece of feedback, and take your input very seriously. Saved searchesUse saved searches to filter your results more quickly. To see all available qualifiers, see our documentation . - Notifications You must be signed in to change notification settings
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 warning: assignment discards ‘const’ qualifier from pointer target type #107osalbahr commented Nov 22, 2023 Hello, I noticed the following when upgrading my system: Just wanted to double-check if this warning is expected. | The text was updated successfully, but these errors were encountered: | davidjo commented Nov 22, 2023 yes this is an expected error - I seem to remember at the time I couldnt figure a way to remove this warning. | Sorry, something went wrong. davidjo commented Jan 24, 2024Successfully merging a pull request may close this issue. Little-Prince解决 assignment discards 'const' qualifier from pointer target type 的问题. 用上述语句调用外部库函数 "external_library_function" 编译时总是报 这种情况说明该函数返回的是一个指向常量或变量的指针,修改十分容易,只需要将 "fr" 的定义改为 const float, 问题解决了,但还是要进一步思考指针和 const 一起用时的几个注意点: 1. const float *p p 是指向常量或变量的指针, 指向可以改变。 2. float *const p p不可以指向常量或常变量,指向确定后不可更改。 3. const float *const p p可以指向常量或变量,指向确定后不可更改。 posted on 2020-06-27 11:41 Little-Prince 阅读( 5513 ) 评论( 0 ) 编辑 收藏 举报 Powered by: 博客园 Copyright © 2024 Little-Prince Powered by .NET 8.0 on Kubernetes - 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 OverflowFind 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. assignment discards ‘const’ qualifier from pointer target type - When trying to retrieve a valueCouchbase uses an event-based model. So in order to retrieve values I have to set up a call-back handler and then throw a get-request at the database. It is done like this: In the get_callback I have a cookie to put my values into. So I parse the object I get back and put it into the cookie via: When I want to retrieve it I have to use lcb_get_cookie man page which returns a void pointer but says: "lcb_get_cookie() returns the value set by lcb_set_cookie(), or NULL if no value is set by lcb_set_cookie()." So I want to do something like: When I try to use it like this I get a warning: warning: assignment discards ‘const’ qualifier from pointer target type [enabled by default] . So I'm confused. How can I retrieve the value I put into the cookie? Edit: I forgot to mention that I need to further process the data and want to make changes to it. Tell compiler that you promise not to change that cookie: But if you need to change it, you could perhaps cast it, because manual says that "...libcouchbase will not do anything with the value." : But maybe safer alternative would be to copy the contents to a new cookie, make changes and set it again? I don't know the exact layout of json_t , by if it does not contain any internal pointers, simple assignment might do the trick: - That's the thing. I want to make changes to it. I forgot to mention it and will edit my question. – Sören Titze Commented Oct 3, 2013 at 11:53
- I like the idea of copying it. How would I go about doing it? My grasp of C is still very rudimental. - Thank you for your quick and thorough help good sir! – Sören Titze Commented Oct 3, 2013 at 12:03
Your AnswerReminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more Sign up or log inPost 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 couchbase or ask your own question .- The Overflow Blog
- Where does Postgres fit in a world of GenAI and vector databases?
- 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
- What does a new user need in a homepage experience on Stack Overflow?
- Feedback requested: How do you use tag hover descriptions for curating and do...
- Staging Ground Reviewer Motivation
Hot Network Questions- How do you determine what order to process chained events/interactions?
- Should I report a review I suspect to be AI-generated?
- Dress code for examiner in UK PhD viva
- My visit is for two weeks but my host bought insurance for two months is it okay
- Exact time point of assignment
- What to call a test that consists of running a program with only logging?
- The answer is not wrong
- Variable usage in arithmetic expansions
- Could someone tell me what this part of an A320 is called in English?
- Is having negative voltages on a MOSFET gate a good idea?
- Topology on a module over a topological ring
- What explanations can be offered for the extreme see-sawing in Montana's senate race polling?
- What was I thinking when I made this grid?
- Why does Russia strike electric power in Ukraine?
- `Drop` for list of elements of different dimensions
- What prevents a browser from saving and tracking passwords entered to a site?
- Passport Carry in Taiwan
- Why doesn't the world fill with time travelers?
- 3 Aspects of Voltage that contradict each other
- How Can this Limit be really Evaluated?
- Fill a grid with numbers so that each row/column calculation yields the same number
- DATEDIFF Rounding
- What did the Ancient Greeks think the stars were?
- My colleagues and I are travelling to UK as delegates in an event and the company is paying for all our travel expenses. what documents are required
Public signup for this instance is disabled . Go to our Self serve sign up page to request an account. video.c:63:22: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]- Status: Closed
- Resolution: Duplicate
- Affects Version/s: 1.5.0
- Fix Version/s: None
- Component/s: guacamole
- Labels: None
- Environment: Ubuntu 22.10
DescriptionHello under latest ubuntu when i update guacamole from 1.4 to 1.5 when i write "sudo make" in guacamole-server i have this error: ps: i have installed libavformat-dev and ffmpeg package make [2] : Entering directory '/home/kpietrasiak/guacamole-server-1.5.0/src/guacd' /usr/bin/mkdir -p '/usr/bin' /bin/bash ../../libtool --mode=install /usr/bin/install -c guacd '/usr/bin' libtool: install: /usr/bin/install -c .libs/guacd /usr/bin/guacd /usr/bin/mkdir -p '/usr/share/man/man5' /usr/bin/install -c -m 644 man/guacd.conf.5 '/usr/share/man/man5' /usr/bin/mkdir -p '/usr/share/man/man8' /usr/bin/install -c -m 644 man/guacd.8 '/usr/share/man/man8' /usr/bin/mkdir -p '/usr/lib/systemd/system' /usr/bin/install -c -m 644 systemd/guacd.service '/usr/lib/systemd/system' make [2] : Leaving directory '/home/kpietrasiak/guacamole-server-1.5.0/src/guacd' make [1] : Leaving directory '/home/kpietrasiak/guacamole-server-1.5.0/src/guacd' Making install in src/guacenc make [1] : Entering directory '/home/kpietrasiak/guacamole-server-1.5.0/src/guacenc' CC guacenc-video.o video.c: In function ‘guacenc_video_alloc’: video.c:63:22: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers] 63 | container_format = container_format_context->oformat; | ^ video.c:66:22: error: initialization discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers] 66 | AVCodec* codec = avcodec_find_encoder_by_name(codec_name); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make [1] : *** [Makefile:1126: guacenc-video.o] Error 1 make [1] : Leaving directory '/home/kpietrasiak/guacamole-server-1.5.0/src/guacenc' make: *** [Makefile:544: install-recursive] Error 1 AttachmentsIssue links. |
IMAGES
COMMENTS
The &str[strIndex-1] expression has type const char*. You are not allowed to assign a const char* value to a char * pointer. That would violate the rules of const-correctness.
You could change the signature of myStrTod so that your output is to a pointer to const char: float myStrTod(const char *nPtr, const char **endPtr); Then GCC will report a different error: 40937624.c: In function 'main': 40937624.c:11:25: warning: passing argument 2 of 'myStrTod' from incompatible pointer type [-Wincompatible-pointer ...
Joined: 23 Jun 2008. Posts: 469 View Posts. I have some code that is giving me a warning... assignment discards qualifiers from pointer target type Here it is... const XCHARItemList [] ="Line1\n ""Line2\n ""Line3\n "; XCHAR* pTemp; pTemp =ItemList ; // <--- warning on this line. Since the code is not working right, I assume that the warning may ...
The "assignment discards 'const' qualifier from pointer target type" warning occurs when you try to assign a pointer to a non-const object to a pointer to a const object. This is because doing so would allow the modification of the const object through the non-const pointer, which is not allowed. For example: In the above example, the compiler ...
Learn why the compiler warns about assigning a constant pointer to a non-constant pointer and how to fix it. See the code example, the explanation and the solution for the strchr function.
I think the most pragmatic solution would be to change the type of sc_apdu_t.data back to const and cast the few occurences where non-const is needed. Windows warnings need to be fixed from peoples using OpenSC Windows.
main.c: In function 'main': main.c:16:9: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 16 | ptr = &j; | ^ *ptr: 10 *ptr: 20 3. Constant Pointer to Variable int* const ptr; The declaration you provided is for a pointer to a constant integer, not a constant pointer to an integer. ...
Wdiscarded-qualifiers: assignment discards 'const' qualifier from pointer target type #6151. Open sgoveas opened this issue May 10, 2022 · 2 comments Open Wdiscarded-qualifiers: assignment discards 'const' qualifier from pointer target type #6151. sgoveas opened this issue May 10, 2022 · 2 comments Labels. Future work Improvement-Tech-Debt.
Options. 2021-06-11 07:15 AM. Volatile means the compiler is prevented from optimizing out accesses to that variable. When the compiler generates code for a function, it does so with this in mine. Removing the qualifier would break this restriction as functions generated without this qualifier would not adhere to the restriction.
warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] new_map[1] = ""; when using squarline studio 1.2.x, even more of such messages show up. Unfortunately, when I try to disable warning by specifying
Nginx Compile Error: "assignment discards 'const' qualifier from pointer target type" #196. Closed PDowney opened this issue Aug 23, 2018 · 3 comments ... error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers] ctx->in_buf->pos = ctx->zstream.next_in; ^
本文介绍了const在指针赋值时候的用法和注意事项,以及如何解决assignment discards 'const' qualifier from pointer target type的错误。文章给出了代码示例和解释,以及总结了const数据和非const数据的地址的赋值规则。
Solution 1. You only have a const void* and assign that to a void*. Hence you can modify the target with pt_SAP->pt_param although you could not with pt_Param. This breaks the contract of the function parameter declaration, which "promises" not to modify the object to which pt_Param pointer. And hence the warning. Nice explanation, 5ed.
main.c: In function 'main': main.c:16:9: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 16 | ptr = &j; | ^ *ptr: 10 *ptr: 20 3. Constant Pointer to Variable int* const ptr; The above declaration is a constant pointer to an integer variable, which means we can change the value of the ...
Here is basically what the code looks like: char *str; str = Inet_ntop (...); //returns const char * It's warning you that the "protection" of the pointer's target provided by the 'const' qualifier is lost when the 'const' is thrown away by assigning it to a "plain" type 'char*' pointer.
warning: assignment discards 'const' qualifier from pointer target type #107. Closed osalbahr opened this issue Nov 22, 2023 · 2 comments ... assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 1193 | hinfo = spec->gen.stream_analog_playback; | ^ At main.c:167: ...
本文介绍了如何解决编译时出现的 assignment discards 'const' qualifier from pointer target type 的警告,以及指针和 const 的用法和注意点。给出了一个外部库函数的例子,以及 const float *p, float *const p, const float *const p 三种指针定义的区别和用法。
When I try to use it like this I get a warning: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]. So I'm confused. How can I retrieve the value I put into the cookie? Edit: I forgot to mention that I need to further process the data and want to make changes to it.
Public signup for this instance is disabled.Go to our Self serve sign up page to request an account.