Obteniendo el error 'char16_t y char32_t no declarados'

I am developing a program in C++ on Linux. The gcc version is 4.5.1 20100924. I want to use std::atomic_int in my program. I have included atomic header as below:

include <atomic>

When I compile the program I get below errors:

In file included from /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomic_base.h:87:0,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/atomic:41,
                 from ../Source/Main.h:33:
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:107:25: error: ‘char16_t’ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:107:33: error: template argument 1 is invalid
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:107:53: error: invalid type in declaration before ‘;’ token
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:110:25: error: ‘char32_t’ was not declared in this scope
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:110:33: error: template argument 1 is invalid
/usr/lib/gcc/x86_64-redhat-linux/4.5.1/../../../../include/c++/4.5.1/bits/atomicfwd_cxx.h:110:53: error: invalid type in declaration before ‘;’ token

Si incluyo <cstdint>, I get the same errors. The headers uchar.h and cuchar.h are not there on my system. How can I resolve the compilation errors?

Gracias de antemano.

preguntado el 31 de julio de 12 a las 15:07

Are you passing the option -std=c++0x? -

cuchar.h is not a header, just cuchar. De todos modos, charXX_t are "builtin" types, no include is not needed. -

Passing -std=c++0x to g++ solved the problem. Thanks a lot. -

I also suggest to upgrade the compiler; current version of GCC is 4.7, and 4.6 appeared in march 2011; since you want C++2011 features it is better to upgrade. -

2 Respuestas

EDITADO:

I was wrong about that. just pass --std=c++0x to g++, and that would do it.

Respondido 31 Jul 12, 15:07

@LokiAstari Yep that's true dude. And my apologies. - estrellar

@Loki: As far as I see it, the standard defines them as keywords, no need for an extra include. cuchar does not define types/aliases. - Sebastián Mach

@geekowl: Almost a rant: This answer gives a fish after at first giving just some rotten fish. The other answer gives fish and some info about how to fish. Yet, the other wasn't accepted. - Sebastián Mach

Aren't you supposed to delete your answer when you realize you were wrong and someone else was right? - cappjc

I think chappjc is right. Completely changing ones answer to the tune of an existing answer is not good manner :P - Sebastián Mach

You seem to not have enabled C++11 support in your compiler or you use a compiler that has these new types not declared.

Para char16_t y char32_t, you need no extra include.


g++ howto:

Tipo g++ --version. If it is at least 4.4, then it has support for nuevos literales de cadena. If not: You need a newer compiler version.

Then, make sure to pass --std=c++0x or --std=c++11 al compilador.

Respondido 31 Jul 12, 15:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.