gcc

sbrk(0) value getting increased after calling printf

青春壹個敷衍的年華 提交于 2021-02-11 07:43:36
问题 I am trying to write my own malloc implementation, following an online course. Issue I am facing is that i always get segmentation fault, and when i tried to debug it always point to printf statement, which is just a string. After further investigation i found the value for sbrk(0) always increase after printf gets called. I am not sure but i think my malloc implementation overwrites some memory space that printf might be using. But is it possible for printf to be there. The program works

How to correctly define and link a C++ class destructor to a main file?

牧云@^-^@ 提交于 2021-02-11 07:20:24
问题 This is a particularized question from mingw32/bin/ld.exe ... undefined reference to [class] ... collect2.exe: error: ld returned 1 exit status There is a user-defined class inside MyClass.hpp: class MyClass { public: MyClass(const string& className); ~MyClass() {cout << "Destructor definition instead of g++ default one?";} ; ... and you try to construct an object out of it in the main file: #include "MyClass.hpp" //in the same directory ... int main() { ... MyClass myClassObj = MyClass

How to correctly define and link a C++ class destructor to a main file?

戏子无情 提交于 2021-02-11 07:20:06
问题 This is a particularized question from mingw32/bin/ld.exe ... undefined reference to [class] ... collect2.exe: error: ld returned 1 exit status There is a user-defined class inside MyClass.hpp: class MyClass { public: MyClass(const string& className); ~MyClass() {cout << "Destructor definition instead of g++ default one?";} ; ... and you try to construct an object out of it in the main file: #include "MyClass.hpp" //in the same directory ... int main() { ... MyClass myClassObj = MyClass

Compile-Time Function Execution

廉价感情. 提交于 2021-02-11 05:54:49
问题 Is there a way to perform compile-time function execution in C? With GCC? I've only seen this available using constexpr in C++. 回答1: As long as there are only constants involved in an expression, it will get calculated at compile-time. C++ constexpr is mostly a type safe way of doing so without involving macros. In C, there are only macros. For example: #define CIRCLE_AREA(r) (int32_t)( (double)(r) * (double)(r) * M_PI ) int32_t area = CIRCLE_AREA(5); performs all calculations at compile-time

GCC with Cygwin/Win7: missing syscall.h

假如想象 提交于 2021-02-10 20:22:56
问题 I am trying to compile a linux c++ source code on Windows 7 Cygwin and getting following error: $ make getconf: Unrecognized variable `LFS_CFLAGS' gcc -O3 -Wall -Wextra -g -DVERSION='"v1.1.0"' -c src/main.c -o src/main.o src/main.c:10:25: schwerwiegender Fehler: sys/syscall.h: No such file or directory #include <sys/syscall.h> ^ Kompilierung beendet. Makefile:48: recipe for target 'src/main.o' failed make: *** [src/main.o] Error 1 I googled this but hadn't any success. Any ideas? 回答1: syscall

GCC with Cygwin/Win7: missing syscall.h

ⅰ亾dé卋堺 提交于 2021-02-10 20:19:30
问题 I am trying to compile a linux c++ source code on Windows 7 Cygwin and getting following error: $ make getconf: Unrecognized variable `LFS_CFLAGS' gcc -O3 -Wall -Wextra -g -DVERSION='"v1.1.0"' -c src/main.c -o src/main.o src/main.c:10:25: schwerwiegender Fehler: sys/syscall.h: No such file or directory #include <sys/syscall.h> ^ Kompilierung beendet. Makefile:48: recipe for target 'src/main.o' failed make: *** [src/main.o] Error 1 I googled this but hadn't any success. Any ideas? 回答1: syscall

makefile error: make: *** No rule to make target `omp.h' ; with OpenMP

旧巷老猫 提交于 2021-02-10 19:52:44
问题 all, I was compiling a C program with OpenMP. It's my first time to use makefile. When excuting "make", the gcc reports the error make: * No rule to make target omp.h', needed by smooth.o'. Stop. However the omp.h is in the /usr/lib/gcc/i686-linux-gnu/4.6/include/omp.h , I am wondering how to fix it. Could anyone help me? Thank you. CC=gcc CFLAGS = -fopenmp all: smooth smooth: smooth.o ompsooth.o $(CC) $(CFLAGS) -o smooth smooth.o ompsmooth.o ompsmooth.o: ompsmooth.c assert.h stdio.h stdlib.h

Why does sqrt() work fine on an int variable if it is not defined for an int?

大兔子大兔子 提交于 2021-02-10 12:19:40
问题 In chapter 3 of Programming: Principles and Practice using C++ (sixth printing), Stroustrup states (p.68): "Note that sqrt() is not defined for an int " . Here is a simple C++ program based on that chapter: #include "std_lib_facilities.h" int main() { int n = 3; cout << "Square root of n == " << sqrt(n) << "\n"; } Given the quote above, I would expect the process of compiling or running this program to fail in some way. To my surprise, compiling it (with g++ (GCC) 4.2.1) and running it

why does “+=” gives me unexpected result in SSE instrinsic

五迷三道 提交于 2021-02-10 11:51:43
问题 There are two ways of implementation of accumulation in sse intrinsic. But one of them gets the wrong result. #include <smmintrin.h> int main(int argc, const char * argv[]) { int32_t A[4] = {10, 20, 30, 40}; int32_t B[8] = {-1, 2, -3, -4, -5, -6, -7, -8}; int32_t C[4] = {0, 0, 0, 0}; int32_t D[4] = {0, 0, 0, 0}; __m128i lv = _mm_load_si128((__m128i *)A); __m128i rv = _mm_load_si128((__m128i *)B); // way 1 unexpected rv += lv; _mm_store_si128((__m128i *)C, rv); // way 2 expected rv = _mm_load

why does “+=” gives me unexpected result in SSE instrinsic

爷,独闯天下 提交于 2021-02-10 11:51:32
问题 There are two ways of implementation of accumulation in sse intrinsic. But one of them gets the wrong result. #include <smmintrin.h> int main(int argc, const char * argv[]) { int32_t A[4] = {10, 20, 30, 40}; int32_t B[8] = {-1, 2, -3, -4, -5, -6, -7, -8}; int32_t C[4] = {0, 0, 0, 0}; int32_t D[4] = {0, 0, 0, 0}; __m128i lv = _mm_load_si128((__m128i *)A); __m128i rv = _mm_load_si128((__m128i *)B); // way 1 unexpected rv += lv; _mm_store_si128((__m128i *)C, rv); // way 2 expected rv = _mm_load