clang

macOS 下的 getch()

*爱你&永不变心* 提交于 2020-02-27 09:48:38
macOS 下的 getch() 作者: 高延( https://my.oschina.net/u/593709 ) 时间: 2020-01-14 下午 我想在c语言写的某程序实现 “按下任意键继续...”。这在windows 下好实现,用getch()就行了。 但是,macOS 用同样的办法,clang 提示找不到头文件 conio.h。 ('conio.h' file not found) 百度之,发现多种方法,比较简单的是使用 curses 库: "在linux中使用getch()函数" 这个方法在 macOS 中同样有效 代码: ... #include <curses.h> int main() { initscr(); //这行与 endwin() 成对,使用curses必须这样 ... getch(); ... endwin(); //结束 curses } 编译: clang -lcurses -o xxx xxx.c 执行: ./xxx OK,想要的结果有了,但是多出来东西了,它清屏了😳。 这不是我期待的。于是,继续百度,似乎没有简洁如此的方法了。我bing还不行吗。好的,找到某人写的 myconio, 下载解压,将myconio_mac.h 和 myconio_mac.c 复制到代码路径,引用之: ... #include <myconio_mac.h> int

应用 AddressSanitizer 发现程序内存错误

无人久伴 提交于 2020-02-27 08:29:21
应用 AddressSanitizer 发现程序内存错误 作为 C/ C++ 工程师,在开发过程中会遇到各类问题,最常见便是 内存使用问题 ,比如, 越界 , 泄漏 。过去常用的工具是 Valgrind,但使用 Valgrind 最大问题是它会极大地降低程序运行的速度,初步估计会降低 10 倍运行速度。而 Google 开发的 AddressSanitizer 这个工具很好地解决了 Valgrind 带来性能损失问题,它非常快,只拖慢程序 2 倍速度。 AddressSanitizer 概述 AddressSanitizer 是一个基于编译器的测试工具,可在运行时检测 C/C++ 代码中的多种内存错误。严格上来说,AddressSanitizer 是一个编译器插件,它分为两个模块,一个是编译器的 instrumentation 模块,一个是用来替换 malloc/free 的动态库。 Instrumentation 主要是针对在 llvm 编译器级别对访问内存的操作(store,load,alloc等),将它们进行处理。动态库主要提供一些运行时的复杂的功能(比如 poison/unpoison shadow memory)以及将 malloc/free 等系统调用函数 hook 住。 AddressSanitizer 基本使用 根据 AddressSanitizer Wiki

Find parent of a declaration in Clang AST

时光毁灭记忆、已成空白 提交于 2020-02-27 07:36:09
问题 I'm using clang to do some analysis and I need to find parent of a declaration in AST. For instance, in the following code I have int x and I want to get its parent which should be the function declaration : int main(int x) { return 0 } I know as mentioned in this link http://comments.gmane.org/gmane.comp.compilers.clang.devel/2152 there is a ParentMap class to track parent nodes. However, this just represents a map from Stmt* -> Stmt* and I need to find parent of a declaration. Does anyone

How to use compile_commands.json with clang python bindings?

南楼画角 提交于 2020-02-27 06:50:50
问题 I have the following script that attempts to print out all the AST nodes in a given C++ file. This works fine when using it on a simple file with trivial includes (header file in the same directory, etc). #!/usr/bin/env python from argparse import ArgumentParser, FileType from clang import cindex def node_info(node): return {'kind': node.kind, 'usr': node.get_usr(), 'spelling': node.spelling, 'location': node.location, 'file': node.location.file.name, 'extent.start': node.extent.start,

Mac安装lightgbm导入import时报错的解决方案

こ雲淡風輕ζ 提交于 2020-02-27 03:50:44
OSError : dlopen(/Users/user/anaconda3/lib/python3.7/site-packages/lightgbm/lib_lightgbm.so, 6): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib Referenced from: /Users/user/anaconda3/lib/python3.7/site-packages/lightgbm/lib_lightgbm.so Reason: image not found 尝试了 https://stackoverflow.com/questions/29910217/homebrew-installation-on-mac-os-x-failed-to-connect-to-raw-githubusercontent-com 的方法,无效 继续花半小时排坑 https://blog.csdn.net/weixin_32087115/article/details/81489627 的方法,无效 后查阅官方文档—— For macOS users: Starting from version 2.2.1, the library file in distribution wheels is built by the

Python学习06.08:Python类调用实例方法

淺唱寂寞╮ 提交于 2020-02-26 22:51:27
通过前面的学习,类方法大体分为 3 类,分别是类函数、实例函数和静态函数,其中实例函数用的是最多的。我们知道,实例函数的调用方式其实有 2 种,既可以采用类对象调用,也可以直接通过类名调用。 通常情况下,我们习惯使用类对象调用类中的实例方法。但如果想用类调用实例方法,不能像如下这样: class CLanguage: def info(self): print("我正在学 Python") # 通过类名直接调用实例方法 CLanguage.info() # 运行以上代码,程序会报错 Traceback (most recent call last): File "D:\python3.6\demo.py", line 5, in <module> CLanguage.info() TypeError: info() missing 1 required positional argument: 'self' 其中,最后一行报错信息提示我们,调用 info() 类方式时缺少给 self 参数传参。这意味着,和使用类对象调用实例方法不同, 通过类名直接调用实例方法时,Python 并不会自动给 self 参数传值。 因此,如果想通过类名直接调用实例方法,就必须手动为 self 参数传值。例如修改上面的代码为: class CLanguage: def info(self): print

如何检查NSDictionary或NSMutableDictionary是否包含密钥?

纵饮孤独 提交于 2020-02-26 17:12:25
我需要检查dict是否有密钥。 怎么样? #1楼 是。 这种错误很常见,导致应用程序崩溃。 所以我用它在每个项目中添加NSDictionary,如下所示: //.h文件代码: @interface NSDictionary (AppDictionary) - (id)objectForKeyNotNull : (id)key; @end //.m文件代码如下 #import "NSDictionary+WKDictionary.h" @implementation NSDictionary (WKDictionary) - (id)objectForKeyNotNull:(id)key { id object = [self objectForKey:key]; if (object == [NSNull null]) return nil; return object; } @end 在代码中,您可以使用如下: NSStrting *testString = [dict objectForKeyNotNull:@"blah"]; #2楼 一个非常讨厌的问题,只是浪费了我的一些时间调试 - 你可能会发现自己提示自动完成尝试使用似乎工作的 doesContain 。 除此之外, doesContain 使用一个ID比较,而不是使用哈希比较 objectForKey 所以

invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'const char *') [closed]

◇◆丶佛笑我妖孽 提交于 2020-02-26 11:59:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . When trying to compile my c++ code with Cheerp (using clang++), I get this output from my terminal: example.cpp:102:9: error: invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'const char *') out << "(" << loc.x << ", " << loc.y << ")"; ~~~ ^ ~~~ Here is my command to the

Python学习06.06:Python类变量和实例变量

送分小仙女□ 提交于 2020-02-26 10:56:42
无论是类变量还是类函数,都无法向普通变量或者函数那样,在类的外部直接使用它们。我们可以将类看做一个独立的空间。 前面章节提到过,在类体中,根据变量定义的位置不同,以及定义的方式不同,类变量又可细分为以下 3 种类型: 类体中、所有函数之外:此范围定义的变量,称为 类变量 ; 类体中,所以函数内部:以“self.变量名”的方式定义的变量,称为 实例 变量 ; 类体中,所有函数内部:以“变量名 = 变量值”的方式定义的变量,称为 局部变量 。 那么,类变量、实例变量以及局部变量之间有哪些不同呢?接下来就围绕此问题做详细地讲解。 类变量 类变量指的是在类中,但在各个类方法外定义的变量。举个例子: class CLanguage : # 下面定义了2个类变量 name = "C语言中文网" add = "http://c.biancheng.net" # 下面定义了一个say实例方法 def say(self, content): print(content) 上面程序中,name 和 add 就属于类变量。 类变量的特点是,所有类的实例化对象都同时共享类变量,也就是说,类变量在所有实例化对象中是作为公用资源存在的。类方法的调用方式有 2 种,既可以使用类名直接调用,也可以使用类的实例化对象调用( 注意类调用和实例调用在修改时的不同 )。 比如,在 CLanguage 类的外部

为什么这个程序被三个C ++编译器错误地拒绝了?

泪湿孤枕 提交于 2020-02-26 02:00:12
编写我编写的C ++程序时遇到一些困难。 这个程序非常简单,据我所知,它符合C ++标准中规定的所有规则。 我已经两次阅读整个ISO / IEC 14882:2003以确定。 该计划如下: 这是我尝试使用Visual C ++ 2010编译此程序时收到的输出: c:\dev>cl /nologo helloworld.png cl : Command line warning D9024 : unrecognized source file type 'helloworld.png', object file assumed helloworld.png : fatal error LNK1107: invalid or corrupt file: cannot read at 0x5172 沮丧,我尝试了g ++ 4.5.2,但同样无益: c:\dev>g++ helloworld.png helloworld.png: file not recognized: File format not recognized collect2: ld returned 1 exit status 我认为Clang(版本3.0主干127530)必须工作,因为它因其标准一致性而受到高度赞扬。 不幸的是,它甚至没有给我一个漂亮的,突出显示的错误消息: c:\dev>clang++