以下代码:
#include <stdio.h>
inline int myfunc (int x) {
return x+3;
}
int main () {
printf("%d", myfunc(2));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我使用-std=gnu99标志时不编译(我正在用gcc编译).这是它抛出的错误:
gcc -std=gnu99 -c main.c -o main.o
gcc -std=gnu99 main.o -o main
main.o: In function `main':
main.c:(.text+0x15): undefined reference to `myfunc'
collect2: ld returned 1 exit status
make: *** [main] Error 1
Run Code Online (Sandbox Code Playgroud)
-std=gnu99省略时编译没有问题.有谁知道链接器为什么会抱怨-std=gnu99使用?
我正在尝试使用gcc的-Wpadded选项来了解gcc是否可以帮助我找出结构是否填充.这是以下代码.
#include<stdio.h>
struct my {
char *name;
int age;
} my_details;
int main() {
struct my person1;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我使用以下代码编写了代码.gcc -Wpadded alignment_demo.c.它没有返回任何警告.那么我的结构没有填充或我遗失了什么?man gcc但是显示它支持一个名为-Wpadded的选项.请帮助
谢谢奇丹巴拉姆
我有一个程序,用作套接字客户端,这是代码
#include <stdio.h>
#include <signal.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sys/socket.h>
#include <netdb.h>
using namespace std;
void signalHandler(const int signal) {
cout << "SIGINT handled" << endl;
exit(EXIT_SUCCESS);
}
void error(const char *msg) {
perror(msg);
exit(0);
}
const string readStr(int descriptor) {
int n = 0;
string cmd = "";
char buffer[256];
memset(buffer, 0, sizeof(buffer));
while ((n = read(descriptor, buffer, 255)) != 0) {
if (n < 0) {
error("Error reading string");
}
// full string …Run Code Online (Sandbox Code Playgroud) 有一些文字,格式如下:
text part1
<br />
text part2
Run Code Online (Sandbox Code Playgroud)
如何使用php regular-expression获取唯一的文本:text part1?非常感谢.
我有一些像这样的代码:
map<int, string> m;
m[1] = "a";
m[2] = "b";
m[3] = "a";
m[4] = "a";
m[5] = "e";
m[6] = "f";
m[7] = "g";
m[8] = "h";
m[9] = "i";
for (it1 = src.begin(); it1 != src.end(); ++it1) {
for (it2 = it1; it2 != src.end(); ++it2) {
if (it2 == it1) {
continue;
}
if (it2->second == it1->second) {
fprintf(stderr, "%u\n", it2->first);
src.erase(it2);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我使用map,因为元素并不总是按此顺序(1,2 ...)
所以这是问题
在某些地图值的情况下,此代码打印此信息
2
3
4
6
7
8 …Run Code Online (Sandbox Code Playgroud)