我编写了这段代码,通过令牌连接创建包含通用字符名称的标识符.
//#include <stdio.h>
int printf(const char*, ...);
#define CAT(a, b) a ## b
int main(void) {
//int \u306d\u3053 = 10;
int CAT(\u306d, \u3053) = 10;
printf("%d\n", \u306d\u3053);
//printf("%d\n", CAT(\u306d, \u3053));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个代码适用于gcc 4.8.2 with -fextended-identifiersoption和gcc 5.3.1,但是没有与clang 3.3一起使用时出现错误信息:
prog.c:10:17: error: use of undeclared identifier '??'
printf("%d\n", \u306d\u3053);
^
1 error generated.
Run Code Online (Sandbox Code Playgroud)
和本地clang(Apple LLVM版本7.0.2(clang-700.1.81)),错误消息:
$ clang -std=c11 -Wall -Wextra -o uctest1 uctest1.c
warning: format specifies type 'int' but the argument has type
'<dependent …Run Code Online (Sandbox Code Playgroud) 我正在查看下面的代码,我得到了逻辑,但我似乎无法理解它的用途是什么'0'.
class Solution
{
public:
string addBinary(string a, string b)
{
string s = "";
int c = 0, i = a.size() - 1, j = b.size() - 1;
while(i >= 0 || j >= 0 || c == 1)
{
c += i >= 0 ? a[i --] - '0' : 0;
c += j >= 0 ? b[j --] - '0': 0;
s = char(c % 2 + '0') + s;
c /= 2;
}
return …Run Code Online (Sandbox Code Playgroud) 我有以下结构:
typedef struct __attribute__ ((__packed__))
{
uint16_t a;
uint32_t b;
} st_t;
Run Code Online (Sandbox Code Playgroud)
->“b”成员未对齐。
当我执行以下操作时,gcc 会发出警告:
st_t st;
uint32_t * b_p = &st.b;
*b_p = 0;
Run Code Online (Sandbox Code Playgroud)
警告日志:
taking address of packed member of 'struct <anonymous>' may result in an unaligned pointer value
Run Code Online (Sandbox Code Playgroud)
但是当我执行以下操作时,它不会发出任何警告:
st_t st;
st_t * st_p = &st;
st_p->b = 0;
Run Code Online (Sandbox Code Playgroud)
我不明白为什么在第二种情况下它不会发出警告,因为我仍在访问未对齐的成员。
我编写此代码是为了使用 ACPI 从我从 64 位 UEFI 启动的程序中关闭计算机。
(抱歉代码太长,但我认为所有部分都是必要的)
#include <stdint.h>
#define in8(data, port) __asm__ __volatile__ \
("xor %%eax, %%eax\n\tin %%dx, %%al\n\t" : "=a"(data) : "d"(port))
#define in16(data, port) __asm__ __volatile__ \
("xor %%eax, %%eax\n\tin %%dx, %%ax\n\t" : "=a"(data) : "d"(port))
#define out8(data, port) __asm__ __volatile__ \
("out %%al, %%dx\n\t" : : "a"(data), "d"(port))
#define out16(data, port) __asm__ __volatile__ \
("out %%ax, %%dx\n\t" : : "a"(data), "d"(port))
void initSerialPort(void) {
/* set speed to 115200bps */
out8(0x83, 0x03FB); /* enable LSB/MSB …Run Code Online (Sandbox Code Playgroud) 我认为下面代码的时间复杂度应该是 O(1),因为最坏的情况可能是 log 1000 base 2 或某些确定的值。但我不确定,因为它的时间确实随着输入的变化而变化,并且给定的答案是 O(n),我对他们是如何得到这个感到非常困惑。如果我们增加 n,函数被调用的次数就会减少,那么它是 O(1/n) 吗?有可能吗?
#define LIMIT 1000
void fun2(int n)
{
if (n <= 0)
return;
if (n > LIMIT)
return;
cout<<n<<" ";
fun2(2*n);
cout<<n<<" ";
}
Run Code Online (Sandbox Code Playgroud) 当我在Visual Studio中为Android共享库构建项目时,我收到了一条警告消息.
warning : suggest braces around initialization of subobject
[-Wmissing-braces]
Run Code Online (Sandbox Code Playgroud)
此消息指示仅使用一对大括号的数组初始化语句.
int myArray[ROW][COL] = { 1, 2, 3, 4, 5, 6, ..., 451, 452, 453 };
我不能用两对书写的原因是将来有可能改变ROW和COL的大小.
它运行正常,但我不确定是否可以这样离开项目,因为在为仅Windows应用程序编写代码时,我从未见过这样的警告消息.
我是否必须认真对待这件事?
问题是关于使用第 4 行序列的 DEFAULT 值。
CREATE OR REPLACE SEQUENCE CHANNEL_SEQ START WITH 1 INCREMENT BY 1;
CREATE TABLE "CHANNEL" (
"ID_CHANNEL" NUMBER(18,0) DEFAULT CHANNEL_SEQ.NEXTVAL,
"IS_ACTIVE" VARCHAR2(1 CHAR) NOT NULL,
"BATCH_SIZE" NUMBER(3,0) NOT NULL,
"MAX_DOCS_IN_PROCESS" NUMBER(4,0) NOT NULL,
"RECEIVER_ID" NUMBER(18,0) NOT NULL,
"LAST_POS_SESSION_TIME" DATE,
CONSTRAINT "PK_CHANNEL" PRIMARY KEY ("ID_CHANNEL"),
CONSTRAINT "FK_RECEIVER_ID_CHANNEL" FOREIGN KEY ("RECEIVER_ID") REFERENCES "MSG_OUT"("MSG_OUT_ID"),
CONSTRAINT "CHK_IS_ACTIVE" CHECK (IS_ACTIVE IN ('Y', 'N'))
);
Run Code Online (Sandbox Code Playgroud)
错误消息是:
“SQL 错误:ORA-00984:此处不允许使用列”
欢迎所有帮助和提示。
我正在为一个项目编写一个C++库.它基本上包含一个源文件.我在我的Mac上编写了源文件并用它编译g++ -c source.cpp -o source.o并创建了一个静态库ar rcs libmylib.a source.o.还有一个头文件定义了几个函数接口.
我可以在我自己的Mac上使用这个库编译程序,通过发出g++ myprogram.cpp -o myprogram -lmylib -L .它可以编译和运行没有任何错误.但是,当我简单地将静态库复制到服务器并尝试使用该库编译某些代码时,它不起作用.编译器抱怨没有定义某些函数的定义.很明显,链接器成功找到了库,但它根本找不到定义.
然后我尝试在服务器上编译库源文件并在服务器上编译我的项目.一切都很好.但是,当我将服务器上编译的库复制到我的Mac并尝试使用该库编译我的本地测试程序时,编译器投诉ld: warning: ignoring file ./libmylib.a, file was built for archive which is not the architecture being linked (x86_64): ./libmylib.a并拒绝链接.
令我困惑的是我的Mac和服务器的架构应该是相同的(aka,x86_64),但是在这两台机器上编译的相同源文件不能交换使用.这可能是什么原因?库不应该与基于相同架构的机器兼容吗?
有关系统和编译器的更多详细信息:
我的Mac:
AdvancedMage-3:encryption Andy$ uname -a
Darwin AdvancedMage-3.local 15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64
AdvancedMage-3:encryption Andy$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1
Apple LLVM …Run Code Online (Sandbox Code Playgroud) 我正在运行以下程序:(URL:http://ideone.com/aoJoI5)
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
long long int N=pow(2, 36);
cout << N <<endl;
int count = 0;
cout << "Positions where bits are set : " << endl;
for(int j=0; j<sizeof(long long int)*8; ++j){
if(N&(1<<j)){
++count;
cout << j << endl;
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个程序给我输出为:
68719476736
Positions where bits are set :
31
63
Run Code Online (Sandbox Code Playgroud)
现在我正在使用N = 2 ^ 36,这意味着第36位应该是1而没有别的,但为什么程序给我位置31和63?我的程序有什么问题吗?
我有一个观察结果,如果我们使用N = 2 ^ {exp},其中exp> = 32,它总是给出设置位的位置为31和63.任何人都可以解释为什么会发生这种情况?
我需要一些帮助来访问带有指针的2D数组.
我有8个全局char数组声明如下:
char s1[4][16], s2[4][16], ... , s8[4][16];
Run Code Online (Sandbox Code Playgroud)
它们的值稍后在main函数中设置.
我有一个指向这些数组的8个指针的数组,
char (*s[8])[4][16];
Run Code Online (Sandbox Code Playgroud)
此数组中的每个指针都分配如下:
s[0] = &s1;
s[1] = &s2;
..
..
s[7] = &s3;
Run Code Online (Sandbox Code Playgroud)
现在要访问s1的元素*s[0][i][j],但是我没有获得与s1 相同的值s1.同样适用于情况s2,s3等等.
有人可以告诉我出了什么问题吗?