clang

Clang unable to link files in VS Code

≡放荡痞女 提交于 2020-06-17 14:19:29
问题 I recently started learning C++, and I'm currently trying to test out the header file functionality. I wrote three simple files: headertest.h: #pragma once class Cube { public: double getVolume(); double getSurfaceArea(); void setLength(double length); private: double length_; }; headertest.cpp: #include "headertest.h" double Cube::getVolume() { return length_ * length_ * length_; } double Cube::getSurfaceArea() { return 6 * length_ * length_; } void Cube::setLength(double length) { length_ =

Specifying the DEF file when compiling a DLL with Clang

a 夏天 提交于 2020-06-17 09:39:27
问题 I am trying to compile a DLL using clang in windows clang -shared structs.c -o structs.dll but the symbols aren't being exported.. If I add __declspec(dllexport) to my declarations in structs.h, They symbols are exported to DLL. But instead, I would like to do this using a DEF file (structs.def) I created, But I can't find how I pass the DEF file to clang. Any help is appeciated :/ 回答1: Finally figured it out - We can use the -Wl flag in clang to pass some comma-separated arguments to the

Specifying the DEF file when compiling a DLL with Clang

丶灬走出姿态 提交于 2020-06-17 09:39:26
问题 I am trying to compile a DLL using clang in windows clang -shared structs.c -o structs.dll but the symbols aren't being exported.. If I add __declspec(dllexport) to my declarations in structs.h, They symbols are exported to DLL. But instead, I would like to do this using a DEF file (structs.def) I created, But I can't find how I pass the DEF file to clang. Any help is appeciated :/ 回答1: Finally figured it out - We can use the -Wl flag in clang to pass some comma-separated arguments to the

How to represent clang AST in JSON format?

瘦欲@ 提交于 2020-06-16 06:34:31
问题 clang-check -ast-dump -ast-dump-filter=<function_name> main.c gives a AST (only a function declaration) of the particular code. How can we represent generated AST in JSON format? PS: I Want AST for function declaration only. 回答1: Call clang with the -ast-dump=json argument. This was implemented only recently (May 2019) so you need an up-to-date version of Clang. See https://reviews.llvm.org/D60910 for details. There's also a library to export more lower-level information available via

Is there an alternative for visual C++ __declspec (property declaration attribute) in clang and gcc?

亡梦爱人 提交于 2020-06-14 07:51:08
问题 There is a Microsoft specific extension, which makes it possible to define property getters and setters like this: // declspec_property.cpp struct S { int i; void putprop(int j) { i = j; } int getprop() { return i; } __declspec(property(get = getprop, put = putprop)) int the_prop; }; int main() { S s; s.the_prop = 5; return s.the_prop; } Is there any way to define property declaration attribute with clang or gcc? If I search for __declspec , all I find is __declspec(dllexport) , but I am not

Assemble far calls or far jumps (j* instructions)

我怕爱的太早我们不能终老 提交于 2020-06-12 09:11:27
问题 I'm trying to create a dispatch table which changes the location of some instruction in another address which is allocated by AllocateMemoryOnRemoteProcess . One of the problems that I encountered was almost all of Calls and all kind of Jumps are near and relative and as long as I load the assemblies in new location, then these instructions won't work. As I know I should convert these instructions to far jump or far call one of the solutions that I saw during my googling was using push and

Assemble far calls or far jumps (j* instructions)

断了今生、忘了曾经 提交于 2020-06-12 09:10:49
问题 I'm trying to create a dispatch table which changes the location of some instruction in another address which is allocated by AllocateMemoryOnRemoteProcess . One of the problems that I encountered was almost all of Calls and all kind of Jumps are near and relative and as long as I load the assemblies in new location, then these instructions won't work. As I know I should convert these instructions to far jump or far call one of the solutions that I saw during my googling was using push and

ObjC: proper use of property and synthesize?

冷暖自知 提交于 2020-06-09 05:31:08
问题 Does anyone know why this code is running into compilation errors? I'm compiling it on Catalina using clang. I posted a similar issue here but that was when I was trying to compile using clang on Linux. I thought getA and setA are auto-generated by synthesize. Thanks! #import <Foundation/Foundation.h> @interface A: NSObject @property int a; @end @implementation A { int a; } @synthesize a; @end int main (int argc, char * argv[]) { @autoreleasepool { A *a = [[A alloc] init]; [a setA:99]; int v

Why does a function prototype with an empty argument list conflicts with one that has a char argument?

大兔子大兔子 提交于 2020-05-29 04:05:44
问题 With the code below, both clang and gcc called with -std=c11 complain about conflicting types for foo. int foo(); int main(void) { return foo(0); } int foo(char a) { return a; } According to the answer in https://stackoverflow.com/a/13950800/1078224, in (older?) C standards the type int has been assumed when no variable type was given. However, the C11 standard draft (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf), section 6.7.6.3, $14 says that The empty list in a function

Is an extra move somehow faster when doing division-by-multiplication?

霸气de小男生 提交于 2020-05-26 17:24:11
问题 Consider this function: unsigned long f(unsigned long x) { return x / 7; } With -O3 , Clang turns the division into a multiplication, as expected: f: # @f movabs rcx, 2635249153387078803 mov rax, rdi mul rcx sub rdi, rdx shr rdi lea rax, [rdi + rdx] shr rax, 2 ret GCC does basically the same thing, except for using rdx where Clang uses rcx . But they both appear to be doing an extra move. Why not this instead? f: movabs rax, 2635249153387078803 mul rdi sub rdi, rdx shr rdi lea rax, [rdi + rdx