clang

解决vscode+clang+mingw64下的<float.h>兼容性问题

半城伤御伤魂 提交于 2020-08-10 08:22:40
本人c语言纯萌新一枚,编程环境是vscode+clang+mingw,安装的时候是直接把mingw的文件无冲突合并到LLVM里的,参照: https://www.cnblogs.com/esllovesn/p/10012653.html 。 今日在完成c语言老师布置的作业的时候写了以下代码: #include<stdio.h> #include < float .h> int main( void ) { double dv = 1.0 / 3.0 ; float fv = 1.0 / 3.0 ; printf( " %.4f %.4f\n " , dv, fv); printf( " %.12f %.12f\n " , dv, fv); printf( " %.16f %.16f\n " , dv, fv); printf( " %d %d\n " , FLT_DIG, DBL_DIG);  return 0; } 结果很意外的是,无论是直接插件run code还是F5编译均提示编译失败: In file included from exercises5.c: 2 : In file included from C:\Program Files\LLVM\lib\clang\ 9.0 . 0 \include\ float .h: 31 : C:\Program Files

using c11 standard with clang for use of strcpy_s

烈酒焚心 提交于 2020-08-10 05:28:57
问题 I'm running OS X Sierra and trying to compile a c program that uses strcpy_s , but my installed clang compiler is using the c99 standard, but from what I've read strcpy_s requires c11. Here's the code I'm trying to compile #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char source[] = "Test string"; char destination[50]; if(strcpy_s(destination, sizeof(destination), source)) printf("string copied - %s",destination); return 0; } And here's the command I'm using to

using c11 standard with clang for use of strcpy_s

大憨熊 提交于 2020-08-10 05:28:43
问题 I'm running OS X Sierra and trying to compile a c program that uses strcpy_s , but my installed clang compiler is using the c99 standard, but from what I've read strcpy_s requires c11. Here's the code I'm trying to compile #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char source[] = "Test string"; char destination[50]; if(strcpy_s(destination, sizeof(destination), source)) printf("string copied - %s",destination); return 0; } And here's the command I'm using to

使用 ZeroMQ 消息库在 C 和 Python 间共享数据

你说的曾经没有我的故事 提交于 2020-08-09 12:17:25
ZeroMQ 是一个快速灵活的消息库,用于数据收集和不同编程语言间的数据共享。 作为软件工程师,我有多次在要求完成指定任务时感到浑身一冷的经历。其中有一次,我必须在一些新的硬件基础设施和云基础设施之间写一个接口,这些硬件需要 C 语言,而云基础设施主要是用 Python。 实现的方式之一是 用 C 写扩展模块 ,Python 支持 C 扩展的调用。快速浏览文档后发现,这需要编写大量的 C 代码。这样做的话,在有些情况下效果还不错,但不是我喜欢的方式。另一种方式就是将两个任务放在不同的进程中,并使用 ZeroMQ 消息库 在两者之间交换消息。 在发现 ZeroMQ 之前,遇到这种类型的情况时,我选择了编写扩展的方式。这种方式不算太差,但非常费时费力。如今,为了避免那些问题,我将一个系统细分为独立的进程,通过 通信套接字 发送消息来交换信息。这样,不同的编程语言可以共存,每个进程也变简单了,同时也容易调试。 ZeroMQ 提供了一个更简单的过程: 编写一小段 C 代码,从硬件读取数据,然后把发现的东西作为消息发送出去。 使用 Python 编写接口,实现新旧基础设施之间的对接。 Pieter Hintjens 是 ZeroMQ 项目发起者之一,他是个拥有 有趣视角和作品 的非凡人物。 准备 本教程中,需要: 一个 C 编译器(例如 GCC 或 Clang ) libzmq 库

pgaudit安装过程遇到的一些问题

柔情痞子 提交于 2020-08-09 10:58:17
OS:centos 7.2 PG:11.3 问题一: # make check USE_PGXS=1 make: pg_config: Command not found make: *** No rule to make target `check'. Stop. 处理方法: # yum install postgresql11-devel-11.3 如果安装之后还没有该命令,可以看看环境变量的设置: export PATH=$PATH:/usr/pgsql-11/bin    问题二: # make USE_PGXS=1 gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune

SwiftUI

痞子三分冷 提交于 2020-08-09 05:55:47
简介 消息推送相信在很多人的眼里都不陌生了吧?像即时聊天微信,好友发信息给你时会在顶部弹下小窗口提醒你。也像是在影院APP预订了电影票,在开场前一小时你也会收到提醒。这类推送是需要经过后端发送请求的,需要服务器发送推送请求,又或者使用如极光推送等第三方渠道。 那么如果我们的APP不需要连网呢?这是不是就不能使用消息推送了?不是的,苹果还提供给我们本地消息通知服务,即便APP不连网也能使用,功能也很强大可靠。本地时钟的应用场景很广泛,例如手机上的时钟、日历等。 那么你知道如何去实现它吗?这篇文章将告知你答案,同时以两个小案例作为例子,以便更好地去理解它。 笔者环境 Xcode - Version 11.5 (11E608c) Swift - version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53). 权限获取 UserNotifications 是 iOS10 推出来的框架,因此你只能在 10 或以上的版本使用它。推送服务和以往一样,也是需要用户授权的,当用户同意后才能正常注册消息通知,当用户拒绝时应该引导用户去打开APP的通知权限。利用 requestAuthorization 方法弹出并获取通知权限,接收的参数 options 是具体的授权选项,一般有弹窗、未读数量图标和声音即可,并在回调闭包中可以获取授权结果和错误。

Include-what-you-use工具介绍

我怕爱的太早我们不能终老 提交于 2020-08-08 05:29:21
简介 Include-what-you-use 工具(以下简称 iwyu )是Google推出,基于 Clang 的C/C++工程冗余头文件检查工具。 iwyu 依赖 Clang 编译套件,因此,针对每个 Clang 版本,会有对应的 iwyu 工程分支。 使用该工具的好处 更快的编译。当cpp文件包含冗余头文件时,编译器会读取、预处理和解析更多的代码,如果有模板存在,则会引入更多的代码,这会加大编译构建时间。 更好的重构。假如你准备重构 foo.h ,使得它不再使用 vector ,你很可能会从 foo.h 文件中移除 #include<vector> 。理论上可以这么做,但实际上不行,因为其他文件可能会通过 foo.h 来间接引用 vector ,贸然移除会造成其他文件编译失败。 iwyu 工具可以找到并去掉这种间接引用。 头文件自注释。通过查看必须头文件注释,可知道该功能依赖于其他哪些子功能。 使用前向声明代替 include 语句,减少依赖,减少可执行程序大小 Windows平台下使用 在 Window 平台上,使用如下版本: clang_8.0 iwyu 0.12 Visual Studio 2017 使用预编译LLVM来构建 下载并安装 LLVM-8.0.0 二进制安装包,安装在 D:\Program Files\LLVM 下,使用如下语句来构建: cd iwyu

Unable to link C runtime library (libcmt.lib) using lld-link.exe (Windows)

江枫思渺然 提交于 2020-08-08 04:29:05
问题 I'm writing a language using LLVM. I'd like to avoid having to package clang and simply use the LLVM tools (ex. lld, lld-link). I've been trying to invoke the printf function from my simple IR code ( testinput.ll ): ; ModuleID = 'Test2' source_filename = "entry" @str_0 = private unnamed_addr constant [13 x i8] c"Hello world!\00" declare i32 @printf(i8*, ...) define i32 @main() { entry: %anonymous_10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str_0, i32 0,

block在iOS开发中的用法解析与底层原理

好久不见. 提交于 2020-08-07 21:36:44
1. 前言 Block :带有自动变量(局部变量)的匿名函数。它是C语言的扩充功能。之所以是拓展,是因为C语言不允许存在这样匿名函数。 1.1 匿名函数 匿名函数是指不带函数名称函数。C语言中,函数是怎样的呢?类似这样: int func(int count); 调用的时候: int result = func(10); func就是它的函数名。也可以通过指针调用函数,看起来没用到函数名: int result = (*funcptr)(10); 实际,在赋值给函数指针时,必须通过函数的名称才能获得该函数的地址。完整的步骤应该是: int (*funcptr)(int) = &func; int result = (*funcptr)(10); 而通过Block,就能够使用匿名函数,即不带函数名称的函数。 1.2 带有自动变量 关于“带有自动变量(局部变量)”的含义,这是因为Block拥有捕获外部变量的功能。在Block中访问一个外部的局部变量,Block会持用它的临时状态,自动捕获变量值,外部局部变量的变化不会影响它的的状态。 捕获外部变量,看一个经典block面试题: int val = 10; void (^blk)(void) = ^{ printf("val=%d ",val); }; val = 2; blk(); 上面这段代码,输出值是:val = 10,而不是2。

build LLVM example: Undefined symbols for architecture x86_64

南楼画角 提交于 2020-08-06 04:01:47
问题 I've installed LLVM on my laptop but having problem compiling the Fibonacci example in llvm/examples/Fibonacci : clang++ -std=c++11 -I ../../include fibonacci.cpp -o fib /usr/local/include/llvm/Support/DataTypes.h:57:3: error: "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h" According to this question, I add some driver flags: clang++ fibonacci.cpp -std=c++11 -I ../../include -o fib -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS Different errors produced: Undefined