我经常看到使用uint32,uint64等类型的源代码,我想知道它们是应该由程序员在应用程序代码中定义,还是在标准的lib头文件中定义.
在我的应用程序源代码上使用这些类型的最佳方法是什么?
编辑2:问题不是一个简单的印刷错误.我在下面的日志中写了一个错字,我纠正了,但问题仍然存在.
编辑:在尝试下面之后,我错误地用gcc而不是g ++运行了一次.之前使用g ++存在问题,它现在存在.
我目前正在使用MacOS High Sierra盒子.我最近把很多文件从MacBook Air移到了这台机器上,包括我认为是Xcode的所有垃圾.现在,当我尝试编译一个非常简单的C++程序时:
#include <iostream>
int main()
{
// VAR_DEC
int a = 4;
// VAR_MANIP
a = a*2;
// VAR_PRINT
std::cout << a << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到以下荒谬的错误:
jrfarah@Josephs-MBP: [config_file_script] $ g++ test.cpp -o test
In file included from test.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream:38:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/ios:216:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__locale:15:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string:470:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/string_view:171:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/__string:56:
In …Run Code Online (Sandbox Code Playgroud) 我最近有一个面试问题,我必须实施memcpy.我根据自己的经验使用了memcpy,所以这似乎不是一个棘手的问题.
所以,我开始实现一个循环,一次从指针到指针复制一个地址,如下所示:
void memcpy(void* dest, void* src, int size){
for(int index = 0; index < size; index++){
dest[index] = src[index];
}
}
Run Code Online (Sandbox Code Playgroud)
然而,采访者打断说memcpy的man页面说"将src中的n个字节复制到dest"(后面我确认)然后想让我用size/4迭代然后用另一个索引循环来获取剩余的<size%4(我猜假设它是一个32位系统?)
好吧,这看起来很奇怪,因为我多年来一直使用memcpy而没有给它一个*4修饰符没有问题).当我回到家时,我启动了gdb并复制了一个小字符串"hello"并小心地用strlen()和常量输入大小以查看它的起始和停止位置.
char* src = "hello";
char* dest = calloc(16, sizeof(char));
int len = strlen(src);
memcpy(dest, src, len); // both my version and official version
Run Code Online (Sandbox Code Playgroud)
现在我仔细检查了src和dest与gdb,它们都包含"hello\0".
所以我的问题是:对于使用数字4(或"字节大小"),我不理解什么?为什么文档说"n字节"时,那不是真正的行为?我在这里看不清楚什么?
我正在尝试向我学习一些C,并且遇到了可能是一个简单的问题.我正在尝试编译一些包含以下声明的代码:
int32 count;
Run Code Online (Sandbox Code Playgroud)
但是,这会在编译时导致错误:
test.c:21: error: ‘int32’ undeclared (first use in this function)
我需要为gcc设置一个特定的编译时选项,还是一个#include可以解决这个问题的指令?
ps我在Ubuntu Intrepid上运行.
在这个头文件中,我收到错误:未知类型名称 uint32、uint16。我是 Objective-C 的新手,我正在尝试在 Xcode 中导入一个项目。由于上述问题,构建失败。谷歌没有帮助。尝试添加/stdint/stdint.h头搜索路径(xcode 未知类型名称, 未知类型名称'uint8_t',MinGW,Xcode - 如何将 c 库和头文件包含到可可项目中?)。构建仍然失败。
/*-------------------------------------------------------------------------
*
* block.h
* POSTGRES disk block definitions.
*
*
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/storage/block.h,v 1.26 2010/01/02 16:58:08 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef BLOCK_H
#define BLOCK_H
/*
* BlockNumber:
*
* each data file (heap or index) is divided …Run Code Online (Sandbox Code Playgroud)