是否允许srand(0)具有与 相同的效果srand(1)?
C11,7.22.2.2 srand 函数(添加强调):
srand 函数使用参数作为后续调用 rand 返回的新伪随机数序列的种子。
然而,在 glibc 中srand(0)具有相同的效果srand(1):
/* We must make sure the seed is not 0. Take arbitrarily 1 in this case. */
if (seed == 0)
seed = 1;
Run Code Online (Sandbox Code Playgroud)
因此,后续调用会返回相同的伪随机数序列rand,这令人困惑。
额外:我们看到在 MSVC 中srand(0)并没有与srand(1).
步骤是:
\ntar zxf glibc-2.28.tar.gz && cd glibc-2.28\nmkdir build && cd build\n\n../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin\n\nmake -j 8\n\nRun Code Online (Sandbox Code Playgroud)\n我得到如下:
\ninux-gnu/12.2.0/include-fixed -isystem /usr/include -D_LIBC_REENTRANT -include /root/source/glibc-2.28/build/libc-modules.h -DMODULE_NAME=libc -include ../include/libc-symbols.h -DTOP_NAMESPACE=glibc \\\n -DGEN_AS_CONST_HEADERS -x c - \\\n -MD -MP -MF /root/source/glibc-2.28/build/tcb-offsets.h.dT -MT '/root/source/glibc-2.28/build/tcb-offsets.h.d /root/source/glibc-2.28/build/tcb-offsets.h'\nIn file included from ../include/pthread.h:1,\n from ../nptl/../nptl_db/thread_db.h:25,\n from ../nptl/descr.h:32,\n from ../sysdeps/x86_64/nptl/tls.h:130,\n from ../sysdeps/unix/sysv/linux/x86_64/sysdep.h:24,\n from <stdin>:1:\n../sysdeps/nptl/pthread.h:744:47: error: argument 1 of type 'struct __jmp_buf_tag *' declared as a pointer [-Werror=array-parameter=]\n …Run Code Online (Sandbox Code Playgroud) 下面是来自着名的LAPACK数值库的Fortran ZHEEVR例程的C包装器:
void zheevr(char jobz, char range, char uplo, int n, doublecomplex* a, int lda, double vl, double vu, int il, int iu, double abstol, double* w, doublecomplex* z, int ldz, int* info)
{
int m;
int lwork = -1;
int liwork = -1;
int lrwork = -1;
int* isuppz = alloc_memory(sizeof(int) * 2 * n);
zheevr_(&jobz, &range, &uplo, &n, a, &lda, &vl, &vu, &il, &iu, &abstol, &m, w, z, &ldz, isuppz, small_work_doublecomplex, &lwork, small_work_double, &lrwork, small_work_int, &liwork, &info);
lwork …Run Code Online (Sandbox Code Playgroud) 我试图在glibc源代码中找到select()源代码(linux,i386 arch),但我找不到任何东西(与所述架构有关)
有人能指出我的select()源代码吗?
我正在编译一个包含一些标准库的代码作为new,cmath等......但是gcc不能包含它们.
我使用python3.2 distutils来构建它.
它给了我这个错误:gcc fatal error: cmath: No such file or directory.我google了一下,可能我的gcc配置不好,必须重新安装.
我试图在我的archlinux pc上重新安装glibc和gcc及其所有依赖项:sudo pacman -S --recursive glibc gcc但没有任何改变.
问题是什么?
我已经下载了glibc的源代码,并且很长一段时间找到函数ceil(),但我找不到它,谁能告诉我它在哪里?
我在哪里可以找到有关如何在glibc源代码中找到某些函数源代码的详细信息.
谢谢.
我使用GNAT在Ubuntu上编译了一个Ada程序.
之后,我尝试了一些使用该程序的测试,并且它运行正常.
但是,当我将其上传到我的Apache(UNIX)网络服务器并尝试运行该程序时,没有输出.为什么会这样?
可能是在Ubuntu上编译的程序在UNIX服务器上不起作用吗?
(抱歉这个愚蠢的问题!)
我用于编译的系统的Linux版本(uname -a):
Linux ubuntu 3.0.0-12-generic #20-Ubuntu x86-64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
系统的Linux版本我想稍后运行该程序(uname -a):
Linux 2.6.37-he-xeon-64gb+1 i686 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
为了在Ubuntu机器上进行编译,我使用:
gnatmake -O3 myprogram -bargs -static
Run Code Online (Sandbox Code Playgroud) 下面的代码有什么问题.对于某些输入和某些特殊输入的崩溃,它运行完全正常吗?
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
struct event {
string date,time,content;
bool is_high_priority;
};
int main() {
event one,two;
one.is_high_priority=false;
char tmp;
ofstream out_file("events" , ios::binary );
cout<<"\nEnter Date(dd.mm) ";
cin>>one.date;
cout<<"\nEnter Time(hh:mm:ss) ";
cin>>one.time;
cout<<"\nenter content";
cin>>one.content;
if(tmp == 't')
one.is_high_priority = true;
else
one.is_high_priority = false;
out_file.write((char*) &one, sizeof(one) );
out_file.close();
ifstream in_file("events" , ios::binary );
in_file.read((char*)&two,sizeof(two));
cout<<two.date<<" "<<two.time<<" "<<two.content<<" "<<two.is_high_priority;
in_file.close();
}
Run Code Online (Sandbox Code Playgroud)
它为这些输入而崩溃:输入日期(dd.mm)ankmjjdn md
输入时间(hh:mm:ss)输入contentsnjs sjnsn
当你在linux中使用malloc内存时,不能保证根据规范将其归零.那么你得到的数据呢?