我不知道数据类型time_t.它是浮动双重还是其他什么?因为如果我想显示它,我需要与之对应的标签printf.我可以从那里处理其余部分进行显示,time_t但我需要知道与之对应的数据类型.
在C++中是否存在大于long long int的类型?
我的编译器是g ++.
在我的程序中,我统计他们想要的文件并发送数据.stat的字段struct都是特殊类型:
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number …Run Code Online (Sandbox Code Playgroud) 我想让我的代码更加平台/实现独立.time_t在编译代码时,我不知道将在平台上实现什么.我如何知道t要确定使用哪种格式说明符的类型?
...
time_t t = time(NULL);
printf("%s", t);
...
Run Code Online (Sandbox Code Playgroud) 我经常会遇到我想要printf使用整数类型的实现定义大小(如ino_t或time_t)的值进行打印的情况.现在,我使用这样的模式:
#include <inttypes.h>
ino_t ino; /* variable of unknown size */
printf("%" PRIuMAX, (uintmax_t)ino);
Run Code Online (Sandbox Code Playgroud)
这种方法到目前为止有效,但它有一些缺点:
有更好的策略吗?
我想知道Microsoft Visual Studio 2010是否支持C99.如果没有,我怎么能使用像intptr_t和的标准类型uintptr_t?
我有这样的事情:
clock_t start, end;
start=clock();
something_else();
end=clock();
printf("\nClock cycles are: %d - %d\n",start,end);
Run Code Online (Sandbox Code Playgroud)
我总是得到一个输出"时钟周期是:0 - 0"
知道为什么会这样吗?
(只是为了给出一些细节,something_else()函数使用montgomery表示执行从左到右的求幂,而且我不确定something_else()函数确实需要一些不可忽略的时间.)
这是在Linux上.uname -a的结果是:
Linux snowy.*****.ac.uk 2.6.32-71.el6.x86_64 #1 SMP Fri May 20 03:51:51 BST 2011 x86_64 x86_64 x86_64 GNU/Linux
ls命令以这种格式打印时间:
Aug 23 06:07
Run Code Online (Sandbox Code Playgroud)
我如何转换,从接收到的时间stat()的mtime()这个格式的本地时间?
CLOCKS_PER_SEC 是否因系统而异,或者它对于操作系统是恒定的还是依赖于该特定系统的处理器?并且还帮我解释我的代码的输出......是吗??
#include<stdio.h>
#include<time.h>
int main()
{
int a;
long int b;
clock_t start, end;
start = clock();
//Code for which the time is to be calculated
for(a=0;;a++)
{
if(a<0)
{
break;
}
}
printf("int : %u\n",a);
for(b=0;;b++)
{
if(b<0)
{
break;
}
}
printf("long int :%u\n",b);
//code is over
end = clock();
//CLOCKS_PER_SECOND : the number of clock ticks per second
printf("Starting Time:%u\n",start);
printf("Ending Time:%u\n",end);
printf("CLOCKS_PER_SEC:%u",CLOCKS_PER_SEC);
printf("\nNumber of clock ticks:%u",(end - start));
printf("\nTotal time:%u",(double)(end - start)/CLOCKS_PER_SEC);
return 0;
} …Run Code Online (Sandbox Code Playgroud) 我想衡量代码和平的执行时间.
我正在使用clock()函数.
这里的例子如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(void) {
clock_t begin=0, end=0;
begin = clock();
printf("hello world!!\n");
end = clock();
printf("Begin %E\n",begin);
printf("End %E\n",end);
printf("Clocks %E\n",end-begin);
printf("Clocks per second %E\n", CLOCKS_PER_SEC);
printf("Time %E\n", (end-begin)/CLOCKS_PER_SEC);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这里输出:
hello world!!
Begin 2.529616E-320
End 2.535545E-320
Clocks 5.928788E-323
Clocks per second 4.940656E-318
Time 0.000000E+00
Run Code Online (Sandbox Code Playgroud)
时间是0!
我做错了什么?输出是否正确?
非常感谢