Suppress warning : Warning 5 initialization discards 'const' qualifier from pointer target type [enabled by default] ct3A

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Atmel Studio 6.2 for SAM3S and SAM3X

 

I need to suppress this warning (like I did with LPC device using #pragma statement).

 

Warning 5    initialization discards 'const' qualifier from pointer target type [enabled by default]    ct3A

 

I looking to documentation and could not find relevent topic how to supress warning.

 

Any advice how?

 

Thanks. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Wouldn't it be better to fix the code so that it doesn't discard the const qualifier in the first place? If the code actually does legitimately discard the const qualifier (I can think of very few situations where this would be the case), use a type cast. A type cast tells the compiler that you know what you're doing, but be sure that you really do know what you're doing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

christop wrote:
Wouldn't it be better to fix the code so that it doesn't discard the const qualifier in the first place?

Absolutey!

 

Sadly, a lot of Atmel's own code - including ASF - is littered with cases that cause this very warning!

 

angry

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Warning 5    initialization discards 'const' qualifier from pointer target type [enabled by default]    ct3A

I have to say that I seriously do not like Microsoft/Atmel's Error List that tries to summaries all the errors and warnings from a build. It shows things in a nonsensical order and seems to hide half the important detail of the error/warning. I find it much better/easier to simply look at the raw build output and just look at the warning/error there. If you do that then code such as this produces the error shown:

$ cat warn.c
const char foo[] = "hello";

void fn(char * str) {
  str[0] = str[1];
}

int main(void) {
  fn(foo);
}
$ gcc warn.c -o warn
warn.c: In function ‘main’:
warn.c:8:3: warning: passing argument 1 of ‘fn’ discards ‘const’ qualifier from pointer target type [enabled by default]
   fn(foo);
   ^
warn.c:3:6: note: expected ‘char *’ but argument is of type ‘const char *’
 void fn(char * str) {
      ^

There's a lot to like about the way in which the raw warning is presented here. First the "warn.c:8:3" tells me that it's line 8 and column 3 where the problem has been seen. Then the:

   fn(foo);
   ^

even shows me what character 3 on line 8 is in case I don't want to bother editing the file to check. It also helpfully tells me that the thing I'm passing does not agree with "warn.c:3:6" - so column 6 on line 3 of the file. And, again, if I'm too lazy to look up what that is it shows me:

 void fn(char * str) {
      ^

And I'm given two text descriptions of what's wrong.

 

Meanwhile that error list style message in AS6 just shows something like:

Warning 5    initialization discards 'const' qualifier from pointer target type [enabled by default]    ct3A

Most of the detail has been lost.

 

If you look to the raw build output find this same warning and look at the additional detail as I just showed you. Now you can find out both the thing that has the const and the point where it is being lost. This should give you a much better clue as to who is at fault here. If the point where it's discarded is in your own code then obviously you can modify that to fix it. If it is in library code where Atmel (as Andy says) seem very loose with their use of "const" then get onto their bugzilla for ASF and report this as an error to them.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
I have to say that I seriously do not like Microsoft/Atmel's Error List that tries to summaries all the errors and warnings from a build. It shows things in a nonsensical order...

Sadly, I thoroughly agree.

 

angry

 

But it's not just Microsoft/Atmel - Eclipse is just as bad!

 

angry

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...