小编RBe*_*eig的帖子

推荐一个c ++ lib来使用http

我需要一个库来处理http(c ++,c).它必须发送和接收http请求.它将在服务器中用于回答http请求.我的客户端 - 服务器交互应该使用REST模型.

c c++ http

1
推荐指数
1
解决办法
312
查看次数

sizeof(结构)混乱

在下面的代码中,

#include<stdio.h>
typedef struct {
    int bit1:1;
    int bit3:4;
    int bit4:4;
} node;

int main(){
    node n,n1,n2,ff[10];

    printf("%d\n",sizeof(node));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我如何预测结构的大小?

c c++

0
推荐指数
1
解决办法
299
查看次数

__thread上的夹板barf,它是C99的一部分

运行夹板

matt@stanley:~/cpfs$ splint -paramuse +gnuextensions cpfs.c
Run Code Online (Sandbox Code Playgroud)

暂停此行:

__thread int cpfs_errno;
Run Code Online (Sandbox Code Playgroud)

解析错误:

cpfs.c:127:13: Parse Error: Non-function declaration: __thread :
               int. (For help on parse errors, see splint -help parseerrors.)
*** Cannot continue.

检查文档和漱口水没有提到__thread.然而,这__thread是C99规范的一部分,据称Splint支持(插入引用).

这里发生了什么?如何识别夹板__thread

c linux gcc splint thread-local-storage

0
推荐指数
1
解决办法
524
查看次数

有没有办法使用链表来简化我的蒙特卡罗代码

Hiya,我的代码目前有三个函数,每个函数产生大量的随机数.我想知道是否有一种方法只需要一个函数返回一个链表或多维数组,使其有点整洁:

(从http://pastebin.com/Y5aE6XKS复制)

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#ifndef RAND_MAX
#define RAND_MAX 2147483648
#endif
#define N 420000

double* rdm_X(void);
double* rdm_Y(void);
double* rdm_Z(void);

void main(void)
{
   double* Random_number_list_X = rdm_X();
   double* Random_number_list_Y = rdm_Y();
   double* Random_number_list_Z = rdm_Z();
   double X[N+1], Y[N+1], Z[N+1], density = 1, vol = 42.0;
   double sum = 0, sum_x = 0, sum_y = 0, sum_z = 0;
   int i;

   for (i = 0; i <= N; i++) {
      X[i] = 3 * …
Run Code Online (Sandbox Code Playgroud)

c linked-list montecarlo

0
推荐指数
1
解决办法
222
查看次数

isdigit()分段错误

当我尝试在命令行上将数字传递到我的应用程序时,在以下代码上获得奇怪的分段错误.

int offset = 3;

int main(int argc, char *argv[]) {
    // Check for arguments to see whether there is a custom offset
    if (argc == 2) {
        // If argc == 2 then we have a offset?
        if (isdigit((unsigned char)*argv[1])) {
            offset = atoi(*argv[1]);
            printf("Offset changed to: %d\n", offset);
        } else {
            printf("Offset not changed due to %s not being a number.\n", *argv[1]);
        }
    } else if(argc >= 2) {
        // If argc >= 2 then we have too …
Run Code Online (Sandbox Code Playgroud)

c arguments segmentation-fault

0
推荐指数
1
解决办法
2343
查看次数

指定lua参数应该是副本还是引用

我想知道是否有办法指定是否应复制或仅引用lua函数的参数.颜色是表示颜色的对象.

例如,使用此代码

function editColor(col)
    col.r = 0
    print(tostring(col.r))
end

color = Color(255, 0, 0)
print(tostring(color.r))
editColor(color)
print(tostring(color.r))
Run Code Online (Sandbox Code Playgroud)

使输出

255
0
0
Run Code Online (Sandbox Code Playgroud)

所以col是颜色的"参考",但是这段代码:

function editColor(col)
    col = Color(0, 0, 0)
    print(tostring(col.r))
end

color = Color(255, 0, 0)
print(tostring(color.r))
editColor(color)
print(tostring(color.r))
Run Code Online (Sandbox Code Playgroud)

使此输出

255
0
255
Run Code Online (Sandbox Code Playgroud)

所以这里的颜色被复制了.

有没有办法强制复制或引用参数?就像&C++中的运算符一样?

lua reference function

0
推荐指数
1
解决办法
6000
查看次数

2个向量之间的度数?

这个学位计算有什么问题?

我选择了2个矢量,它们的度数应该是90°.

我用cos,cos ^ -1尝试了它,没有cos计算.但是我的代码的输出是:
0(没有cos计算)
1(cosinus)
1.5707963267949(cosinus ^ -1(acos))

local square = math.sqrt;
local weaponVector, hitVector = , {x = 0, y = 0, z = 1,}, {x = 0, y = 1, z = 0,};
local xW, yW, zW = weaponVector.x, weaponVector.y, weaponVector.z;
local xH, yH, zH = hitVector.x, hitVector.y, hitVector.z;
local angleBetweenWeaponAndHitDirection = math.acos(math.abs(xW*xH+yW*yH+zW*zH)
            / (square(xW*xW+yW*yW+zW*zW) * square(xH*xH+yH*yH+zH*zH)));
if (angleBetweenWeaponAndHitDirection>180) then
    angleBetweenWeaponAndHitDirection = 360-angleBetweenWeaponAndHitDirection;
end
print(angleBetweenWeaponAndHitDirection)
print(math.cos(angleBetweenWeaponAndHitDirection))
print(math.acos(angleBetweenWeaponAndHitDirection))
Run Code Online (Sandbox Code Playgroud)

math lua vector

0
推荐指数
1
解决办法
185
查看次数

不熟悉c ++指针,需要帮助

在线上*binSon[0].add(x);,它给我一个错误,一个表达式必须有一个类类型,我该怎么办?

struct Rectangle
{
    tName Name; //name of the rectangle
    struct Rectangle *binSon[NDIR_1D]; //left and right son
    int Center[NDIR_1D];
    int Length[NDIR_1D];

    void add(Rectangle x){
        if(strcmp(x.Name,Name)<0)
        {
            if(binSon[0]==NULL)
                binSon[0]=&x;
            else
                *binSon[0].add(x);

        }else{
            if(binSon[1]==NULL)
                binSon[1]=&x;
            else
                *binSon[1].add(x);
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

c++ pointers

0
推荐指数
1
解决办法
103
查看次数

将char c ='a'转换为int value = 10

拥有这段代码:

int main(void)
{
    char c;
    int hex;
    ....
}
Run Code Online (Sandbox Code Playgroud)

如果c是'a'我想hex成为10.如果c有'f',hex应该是15.我知道如何完成这个任务的整数(c - '0'虽然这不赞成)或字符串(使用sprintfstrtol)但我不知道如何完成这个简单的任务一般.

c hex

0
推荐指数
1
解决办法
591
查看次数

Lua中两个字符串的比较

我试图比较两个字符串,其中第一个字符串是数组的单个元素,第二个数组只是一个常规字符串.出于某种原因,这种比较并非如此.希望有人可以指出我正确的方向!

empty =  "        " 
pawn =   "  Pawn  " 
rook =   "  Rook  " 
knight = " Knight " 
bishop = " Bishop " 
queen =  "  Queen " 
king =   "  King  "

emptyspot = {} 
for i = 1, 8 do
    emptyspot[i] = {}
    for j = 1, 8 do
        emptyspot[i][j] = "    /    "   
    end 
end

function chessBoard() 
    io.write("\n\nWelcome to LuaChess!\n\n") 
    io.write("          1        2        3        4        5        6        7        8    \n") 
    io.write("      *************************************************************************\n") 
    io.write("      *".. empty …
Run Code Online (Sandbox Code Playgroud)

string comparison lua lua-table

0
推荐指数
2
解决办法
5919
查看次数