clang unicode characters for variable name - unicode

cat test.cpp
#include <iostream>
int main() {
int à;
}
results in:
clang++ test.cpp
test.cpp:4:7: error: expected unqualified-id
int à;
^
1 error generated.
Now, is there a way to get clang to allow unicode variable names?
Thanks!

While this is allowed by the standard, Clang does not currently support UCN (universal character name)s in identifiers.

Related

LLDB fails to examine global variables

A global var is defined in my framework
var showersInProgress: [ProgressShower] = []
It's global so that I can stop the program
and hopefully examine the state like so:
(lldb) po showersInProgress
error: <user expression 7>:1:1: use of undeclared identifier 'showersInProgress'
showersInProgress
(lldb) p showersInProgress
error: <user expression 8>:1:1: use of undeclared identifier 'showersInProgress'
showersInProgress
(lldb) frame variable showersInProgress
(lldb) frame showersInProgress
invalid command 'frame showersInProgress'.
(lldb) frame -g showersInProgress
invalid command 'frame -g'.
(lldb) frame -g variable showersInProgress
invalid command 'frame -g'.
(lldb) frame variable -g showersInProgress
(lldb) frame variable -g showersInProgress.count
(lldb)
The log enable -f /tmp/lldb-log.txt lldb expr types
in case it's useful to anyone:
== [UserExpression::Evaluate] Parsing expression showersInProgress ==
ClangUserExpression::ScanContext()
[CUE::SC] Null function
[C++ module config] Language doesn't support C++ modules
List of imported modules in expression:
List of include directories gathered for modules:
Parsing the following code:
#line 1 "<lldb wrapper prefix>"
#ifndef offsetof
#define offsetof(t, d) __builtin_offsetof(t, d)
#endif
#ifndef NULL
#define NULL (__null)
#endif
#ifndef Nil
#define Nil (__null)
#endif
#ifndef nil
#define nil (__null)
#endif
#ifndef YES
#define YES ((BOOL)1)
#endif
#ifndef NO
#define NO ((BOOL)0)
#endif
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef unsigned short unichar;
extern "C"
{
int printf(const char * __restrict, ...);
}
typedef bool BOOL;
void
$__lldb_expr(void *$__lldb_arg)
{
;
#line 1 "<user expression 9>"
showersInProgress
;
#line 1 "<lldb wrapper suffix>"
}
Using x86_64-apple-ios-simulator as the target triple
Using SIMD alignment: 128
Target datalayout string: 'e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128'
Target ABI: ''
Target vector alignment: 128
ClangExpressionDeclMap::FindExternalVisibleDecls[469] for '$__lldb_arg' in a 'TranslationUnit'
CEDM::FEVD[469] Searching the root namespace
ClangASTSource::FindExternalVisibleDecls[469] on (ASTContext*)0x7fb6b48f1800 for '$__lldb_arg' in a 'TranslationUnit'
CAS::FEVD[469] Searching the root namespace
ClangExpressionDeclMap::FindExternalVisibleDecls[470] for '$__lldb_expr' in a 'TranslationUnit'
CEDM::FEVD[470] Searching the root namespace
ClangASTSource::FindExternalVisibleDecls[470] on (ASTContext*)0x7fb6b48f1800 for '$__lldb_expr' in a 'TranslationUnit'
CAS::FEVD[470] Searching the root namespace
ClangExpressionDeclMap::FindExternalVisibleDecls[471] for 'showersInProgress' in a 'TranslationUnit'
CEDM::FEVD[471] Searching the root namespace
Skipped a definition because it has no Clang AST
ClangASTSource::FindExternalVisibleDecls[471] on (ASTContext*)0x7fb6b48f1800 for 'showersInProgress' in a 'TranslationUnit'
CAS::FEVD[471] Searching the root namespace
AppleObjCDeclVendor::FindDecls [434] ('showersInProgress', false, 1, )
AOCTV::FT [434] Couldn't find showersInProgress in the ASTContext
AOCTV::FT [434] Couldn't find the isa
[ClangASTImporter] Forgetting destination (ASTContext*)0x7fb6b48f1800
[ClangASTImporter] Forgetting source->dest (ASTContext*)0x7fb6b48f1800->(ASTContext*)0x7fb69758cc00
frame variable only shows statics in the CompileUnit of the current frame. If you want to see all the globals you need to use target variable. Note, however, target variable only searches the shared library of the current frame. You can add the --shlib flag to direct the search to a specific shared library.

Undefined reference to `ulocdata_open_63'

I am using ICU lib for Exemplar, I am getting undefined ref for `ulocdata_open_63'
I am not using "ulocdata_open_63" function but "ulocdata_open". Library is linked properly.
Why it is looking for ulocdata_open_63 definition even though I am not calling it.
Sample code:-
#include <stdio.h>
#define UNICODE
#include <unicode/uloc.h>
#include <unicode/ulocdata.h>
#include <unicode/urename.h>
typedef unsigned short U16;
int main()
{
char localeID[ULOC_FULLNAME_CAPACITY+ULOC_KEYWORD_AND_VALUES_CAPACITY] = "en_US";
UErrorCode icuStatus = U_ZERO_ERROR;
ULocaleData* uld = ulocdata_open("en", &icuStatus);
...
}
It looks you're linking against a ICU library that was built with ICU version suffixes, which is the default. To build a library without version suffixes you'll have to add the flag --disable-renaming to the configure build step of ICU4C.
See https://unicode-org.github.io/icu/userguide/icu4c/build.html#icu-as-a-system-level-library.

fopen() in S-Function: compilation error [duplicate]

I declared a variable in this way:
int i = 0;
I get the warning:
ISO C90 forbids mixed declarations and code
How can I fix it?
I think you should move the variable declaration to top of block. I.e.
{
foo();
int i = 0;
bar();
}
to
{
int i = 0;
foo();
bar();
}
Up until the C99 standard, all declarations had to come before any statements in a block:
void foo()
{
int i, j;
double k;
char *c;
// code
if (c)
{
int m, n;
// more code
}
// etc.
}
C99 allowed for mixing declarations and statements (like C++). Many compilers still default to C89, and some compilers (such as Microsoft's) don't support C99 at all.
So, you will need to do the following:
Determine if your compiler supports C99 or later; if it does, configure it so that it's compiling C99 instead of C89;
If your compiler doesn't support C99 or later, you will either need to find a different compiler that does support it, or rewrite your code so that all declarations come before any statements within the block.
Just use a compiler (or provide it with the arguments it needs) such that it compiles for a more recent version of the C standard, C99 or C11. E.g for the GCC family of compilers that would be -std=c99.
Make sure the variable is on the top part of the block, and in case you compile it with -ansi-pedantic, make sure it looks like this:
function() {
int i;
i = 0;
someCode();
}
To diagnose what really triggers the error, I would first try to remove = 0
If the error is tripped, then most likely the declaration goes after the code.
If no error, then it may be related to a C-standard enforcement/compile flags OR ...something else.
In any case, declare the variable in the beginning of the current scope. You may then initialize it separately. Indeed, if this variable deserves its own scope - delimit its definition in {}.
If the OP could clarify the context, then a more directed response would follow.
-Wdeclaration-after-statement minimal reproducible example
main.c
#!/usr/bin/env bash
set -eux
cat << EOF > main.c
#include <stdio.h>
int main(void) {
puts("hello");
int a = 1;
printf("%d\n", a);
return 0;
}
EOF
Give warning:
gcc -std=c89 -Wdeclaration-after-statement -Werror main.c
gcc -std=c99 -Wdeclaration-after-statement -Werror main.c
gcc -std=c89 -pedantic -Werror main.c
Don't give warning:
gcc -std=c89 -pedantic -Wno-declaration-after-statement -Werror main.c
gcc -std=c89 -Wno-declaration-after-statement -Werror main.c
gcc -std=c99 -pedantic -Werror main.c
gcc -std=c89 -Wall -Wextra -Werror main.c
# https://stackoverflow.com/questions/14737104/what-is-the-default-c-mode-for-the-current-gcc-especially-on-ubuntu/53063656#53063656
gcc -pedantic -Werror main.c
The warning:
main.c: In function ‘main’:
main.c:5:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
int a = 1;
^~~
Tested on Ubuntu 16.04, GCC 6.4.0.
Ensure you made your declarations before any statements in the block.
For instance:
{
int i = 0;
printf("a string");/*the code is not a working code*/
}
I believe this should be helpful:
https://www.configrouter.com/iso-c90-forbids-mixed-declarations-and-code-in-c-30621/

Why VS2015 intellisense shows error on C++11 user defined literals (UDL)

The below code can be compiled and run, but VS2015 intellisense shows error. g++ & eclipse has the same issue (compiled & run but shows error)
Does anyone know how to fix it? I tried searching on google but hopeless.
The error is a little annoying.. :-)
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
using namespace std::literals;
using namespace chrono_literals;
int main()
{
this_thread::sleep_for(5s);
cout << "test \n";
return 0;
}
Error message: "Invalid suffix 's' on integer literal"
Thanks a lot!
You should add some #include statements and namespace references:
#include <iostream>
#include <chrono>
#include <thread>
int main()
{
using namespace std::literals::chrono_literals;
std::this_thread::sleep_for(5s);
std::cout << "test \n";
return 0;
}
In your code, the compiler is not been told to use namespace std. The 5s does not work without std::literals

Eclipse undefined reference

I'm using Eclipse and MinGW. I've got undefined reference to error to all that I write in h files, that I do include in cpp-file where main located. I create an empty project, and the same thing again (
main.cpp
#include <iostream>
#include "Stack.h"
using namespace std;
int main(){
Stack<int> stack(10);
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
stack.h
#ifndef STACK_H_
#define STACK_H_
template <class T>
class Stack{
private:
struct StackEl;
StackEl *top;
public:
Stack();
Stack(T el);
~Stack();
void Push(const T& el);
T Pop();
};
#endif /* STACK_H_ */
and stack.cpp inplements everything from stack.h
If I include not h-file, but cpp - all works. Help please!
I've got following errors
D:/Workspacee/Stack2/Debug/../src/Stack2.cpp:16: undefined reference to `Stack<int>::Stack(int)'
D:/Workspacee/Stack2/Debug/../src/Stack2.cpp:18: undefined reference to `Stack<int>::~Stack()'
D:/Workspacee/Stack2/Debug/../src/Stack2.cpp:18: undefined reference to `Stack<int>::~Stack()'
This is a linker error. I'm no Eclipse expert, but you have to tell it somehow to add Stack.o to the linking command.
If you include Stack.cpp instead of Stack.h, the implementations from the cpp-file get included into main.cpp by the preprocessor before compilation, so the linking stage has no unresolved references to outside functions.
My bad, that is becouse templates! When you use template, all code, including realization of functions, must be in header-file, or you have to write prototypes for every type you are going to use you template-functions with. I've forgot about that working with templates is not the same as with usual function :(