size-t

What determines how much memory can be allocated?

非 Y 不嫁゛ 提交于 2019-12-25 02:15:57
问题 This is a follow-up to my previous question about why size_t is necessary. Given that size_t is guaranteed to be big enough to represent the largest size of a block of memory you can allocate (meaning there can still be some integers bigger than size_t), my question is... What determines how much you can allocate at once? 回答1: The architecture of your machine, the operating system (but the two are intertwined) and your compiler/set of libraries determines how much memory you can allocate at

C++ self-enforcing a standard: size_t

我的梦境 提交于 2019-12-24 21:39:24
问题 Simple question, Would it be good for me to force myself to start using size_t (or unsigned longs?) in places where I would normally use ints when dealing with arrays or other large datastructures? Say you have a vector pointer: auto myVectorPtr = myVector; Unknown to you, the size of this vector is larger than: std::numeric_limits<int>::max(); and you have a loop: for(int i = 0; i < myVectorPtr->size(); ++i) wouldn't it be preferable to use for(size_t i = 0; i < myVectorPtr->size(); ++i) to

Can we change the size of size_t in C?

偶尔善良 提交于 2019-12-24 02:14:55
问题 Can we change the size of size_t in C? 回答1: size_t is not a macro. It is a typedef for a suitable unsigned integer type. size_t is defined in <stddef.h> (and other headers). It probably is typedef unsigned long long size_t; and you really should not even think about changing it. The Standard Library uses it as defined by the Standard Library. If you change it, as you cannot change the Standard Library , you'll get all kinds of errors because your program uses a different size for size_t than

How to get size_t from string?

故事扮演 提交于 2019-12-23 11:23:02
问题 I need to get an array size from user input. It seemed natural to me to store the input as size_t , however looking for an appropriate strto...() function I couldn't find any. I just used strtoull() , since unsigned long long is guaranteed to be at least 64 bits and I'm using C99 anyway. But I was wondering what would be the best way to get size_t from a string - say, in ANSI C. Edit: To clarify, I don't want the string length! The user will input the size of a large buffer in the form of a

How to get size_t from string?

血红的双手。 提交于 2019-12-23 11:21:22
问题 I need to get an array size from user input. It seemed natural to me to store the input as size_t , however looking for an appropriate strto...() function I couldn't find any. I just used strtoull() , since unsigned long long is guaranteed to be at least 64 bits and I'm using C99 anyway. But I was wondering what would be the best way to get size_t from a string - say, in ANSI C. Edit: To clarify, I don't want the string length! The user will input the size of a large buffer in the form of a

It there an equivalent to size_t in llvm

半世苍凉 提交于 2019-12-22 04:47:21
问题 Some system libraries like malloc strlen want or return size_t as parameter. What is the right choice in LLVM IR to interact with these functions? Is the selection the task for the compiler? Does LLVM IR have a size_t type? 回答1: At the LLVM level, size_t doesn't exist. It is a construct for the benefit of the developer that is typedef'd to a native type. The native types have a fixed size for the target architecture and that is how the compiler represents them in LLVM bit code. So on x86,

What to do with size_t vs. std::size_t?

◇◆丶佛笑我妖孽 提交于 2019-12-22 03:45:17
问题 Having just read: Does "std::size_t" make sense in C++? I realize using ::size_t is not standards-compliant (although supported by my compiler) when you #include <cstddef> . I want to comply with the standard, but I do not want to prepend std:: to all of my size_t 's. So, what is the more customary/popular way to handle this: write using std::size_t; ? include <stddef.h> ? just rely on compiler support? something else? 回答1: You should specify it with the using directive. using std::size_t;

What to do with size_t vs. std::size_t?

一世执手 提交于 2019-12-22 03:45:11
问题 Having just read: Does "std::size_t" make sense in C++? I realize using ::size_t is not standards-compliant (although supported by my compiler) when you #include <cstddef> . I want to comply with the standard, but I do not want to prepend std:: to all of my size_t 's. So, what is the more customary/popular way to handle this: write using std::size_t; ? include <stddef.h> ? just rely on compiler support? something else? 回答1: You should specify it with the using directive. using std::size_t;

printf for size_t

自闭症网瘾萝莉.ら 提交于 2019-12-21 07:04:56
问题 Is there any way to give printf a size_t without either casting it first or generating a compiler warning? (I always compile with -Wall .) 回答1: printf("%zu", sizeof(whatever)); 来源: https://stackoverflow.com/questions/4150056/printf-for-size-t

GCC linaro compiler throws error “unknown type name size_t”

让人想犯罪 __ 提交于 2019-12-20 11:34:10
问题 I am using GCC Linaro compiler for compiling my code. Its throwing the error unknown type name size_t from libio.h . Its included from stdio.h . In my code I am just including stdio.h . Can any one please how to resolve this error. 回答1: As per C99, §7.17, size_t is not a builtin type but defined in <stddef.h> . Including the <stddef.h> header should fix your problem. 回答2: For what it's worth, I had this exact same problem with a QT project, where I was using a Linaro compiler to (on both x86