gcc

Concatenate and stringize macro values for #include

旧街凉风 提交于 2021-02-17 06:22:07
问题 I'm trying to create a string from multiple macros/values for use in a #include . I'm doing this to clean up some code for an initial state in a simple state system. I have 2 default, redefinable macros (if not defined there's a default value) #define DEFAULT_STATE StateName // name of class #define DEFAULT_STATE_LOCATION states/ // location of header file from root The include directive is being used from a file 4 folders in from the root , so the include should look like this #include "../.

opencv compile with clang ok, with gcc not ok os x 10.9

夙愿已清 提交于 2021-02-17 02:06:44
问题 I am on OS X 10.9, with opencv-2.4.8.2 installed. I am trying to compile a simple code: #include <stdio.h> #include <opencv2/opencv.hpp> using namespace cv; int main(int argc, char** argv ) { if ( argc != 2 ) { printf("usage: DisplayImage.out <Image_Path>\n"); return -1; } Mat image; image = imread( argv[1], 1 ); if ( !image.data ) { printf("No image data \n"); return -1; } namedWindow("Display Image", WINDOW_AUTOSIZE ); imshow("Display Image", image); waitKey(0); return 0; } and can do that

opencv compile with clang ok, with gcc not ok os x 10.9

一曲冷凌霜 提交于 2021-02-17 02:06:42
问题 I am on OS X 10.9, with opencv-2.4.8.2 installed. I am trying to compile a simple code: #include <stdio.h> #include <opencv2/opencv.hpp> using namespace cv; int main(int argc, char** argv ) { if ( argc != 2 ) { printf("usage: DisplayImage.out <Image_Path>\n"); return -1; } Mat image; image = imread( argv[1], 1 ); if ( !image.data ) { printf("No image data \n"); return -1; } namedWindow("Display Image", WINDOW_AUTOSIZE ); imshow("Display Image", image); waitKey(0); return 0; } and can do that

What should I fix when Address Sanitizer says detect_leaks is not supported on this platform?

我与影子孤独终老i 提交于 2021-02-16 20:32:22
问题 I'm using Clang to compile my project, on x86_64 OS X(MacOS 10.15.5 Catalina). I want to identify exactly from which file, which function, which line causes memory leaks. I am trying to use Address Sanitizer, specifically Leak Sanitizer. Here are flags that I'm using when compiling: -Wall -Wextra -flto -O3 -march=native -ffast-math -fsanitize=address It successfully compiles. However, when I try to use run-time flag ASAN_OPTIONS=detect_leaks=1 in order to enable Leak Sanitizer, I see the

What should I fix when Address Sanitizer says detect_leaks is not supported on this platform?

梦想的初衷 提交于 2021-02-16 20:32:05
问题 I'm using Clang to compile my project, on x86_64 OS X(MacOS 10.15.5 Catalina). I want to identify exactly from which file, which function, which line causes memory leaks. I am trying to use Address Sanitizer, specifically Leak Sanitizer. Here are flags that I'm using when compiling: -Wall -Wextra -flto -O3 -march=native -ffast-math -fsanitize=address It successfully compiles. However, when I try to use run-time flag ASAN_OPTIONS=detect_leaks=1 in order to enable Leak Sanitizer, I see the

How to use calloc() in C?

余生颓废 提交于 2021-02-16 19:02:50
问题 Shouldn't I get an error if my string goes over 9 characters long in this program? // CString.c // 2.22.11 #include <stdio.h> #include <stdlib.h> #include <string.h> main() { char *aString = calloc(10, sizeof(char)); if (aString == NULL) { return 1; } printf("PLEASE ENTER A WORD: "); scanf("%s", aString); printf("YOU TYPED IN: %s\n", aString); //printf("STRING LENGTH: %i\n", strlen(aString)); } Thanks blargman 回答1: You don't get a compiler error because the syntax is correct. What is

Why does the following code compile using clang but not gcc

这一生的挚爱 提交于 2021-02-16 18:24:47
问题 #include <iostream> #include <unordered_map> #include <string> struct tree_node { // tree_node() : attrib_val{"null"} {} std::unordered_map<std::string, tree_node> child; }; int main(int argc, char const *argv[]) { return 0; } This code compiles just fine on my mac with clang: $ g++ --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.1 (clang

Why does the following code compile using clang but not gcc

点点圈 提交于 2021-02-16 18:24:25
问题 #include <iostream> #include <unordered_map> #include <string> struct tree_node { // tree_node() : attrib_val{"null"} {} std::unordered_map<std::string, tree_node> child; }; int main(int argc, char const *argv[]) { return 0; } This code compiles just fine on my mac with clang: $ g++ --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.1 (clang

Understanding GCC's floating point constants in assembly listing output

陌路散爱 提交于 2021-02-16 13:45:08
问题 Just out of curiosity, I'm using Compiler Explorer to see the assembly output of some simple C++ codes. Consider the following example int main(void){ double x = -5.3; } Assembly output main: push rbp mov rbp, rsp movsd xmm0, QWORD PTR .LC0[rip] movsd QWORD PTR [rbp-8], xmm0 mov eax, 0 pop rbp ret .LC0: .long 858993459 .long -1072352461 I would like to understand how to use .LC0: .long 858993459 .long -1072352461 to get back my -5.3 . My uninformed guess is that I need to merge the bit

为Eclipse添加C/C++开发工具

风流意气都作罢 提交于 2021-02-16 10:46:47
   配置:   1. Eclipse CDT (C/C++ Development Tooling) eclipse CDT 是 Eclipse 插件,它将把 Eclipse 转换为功能强大的 C/C++ IDE。    到http://www.eclipse.org/cdt/downloads.php下载对应版本的CDT   2. Eclipse-> Help->Install New Software->Add   Name 填写 CDT , Location填写下载的CDT位置   勾选CDT Main Features CDT Optional Features    Contact all update sites during install to find required software的√去掉   3. ->Next->Finish, 重启Eclipse ,Help ->About Eclipse, 点选C/C++图标 OK    注意:An error occurred while collecting items to be installed   安装的时候把Contact all update sites during install to find required software的√去掉即可   因为Eclipse是Java写的