strnlen was not declared in this scope for C++11, C++14

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

Hello,

I was trying to enable C++14 support for GCC ARM but discovered that this function cannot compile, works fine if I compile without these flags, but as soon as I add -std=c++14 it fails to compile. Am I missing some definitions to make use of that function?

In the attached example project, in Project properties->Toolchain->Miscellaneous this flag can be added or removed to prove the problem.

 

Thank you in advance,

David.

Attachment(s): 

Last Edited: Wed. Mar 8, 2017 - 04:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A long shot but if you replace:

#include <string.h>
//#include <assert.h>
#include <string>

with

#include <cstring>

what happens?

 

EDIT: BTW I have moved this from the AVR forum for compilers/programming to the ARM version of the same.

Last Edited: Wed. Mar 8, 2017 - 04:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Same compiler error happens with that include. 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include <cstring>

int main(void)
{
	char str[] = "there's a problem compiling this file in C++11";

	int length = strnlen(str, 10);
}

This compiles for me with -std=gnu++14... (strnlen is not part of std)

 

http://www.gnu.org/software/libc/manual/html_node/String-Length.html

:: Morten

 

(yes, I work for Atmel, yes, I do this in my spare time, now stop sending PMs)

Last Edited: Wed. Mar 8, 2017 - 06:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This compiles for me as well, thank you. What I don't understand is why it compiles when -std= is not provided? Is gnu++98 by default enabled?