standard-library

Difference between C standard library and C POSIX library

与世无争的帅哥 提交于 2019-11-27 05:00:31
问题 I'm a little confused by "C standard lib" and "C POSIX lib", because I found that, many header files defined in "C POSIX lib" are also part of "C standard lib". So, I assume that, "C standard lib" is a lib defined by ANSI C organization, and there are different implementation on different platforms (Win32/Unix-like), and "C POSIX lib" is just a implementation for "C standard lib" on Unix-like OSes, right? But "C POSIX lib" contains some headers not specified in "C standard lib", such as <sys

Case Insensitive String comp in C

风格不统一 提交于 2019-11-27 03:31:30
I have two postcodes char* that I want to compare, ignoring case. Is there a function to do this? Or do I have to loop through each use the tolower function and then do the comparison? Any idea how this function will react with numbers in the string Thanks Fred Foo There is no function that does this in the C standard. Unix systems that comply with POSIX are required to have strcasecmp in the header strings.h ; Microsoft systems have stricmp . To be on the portable side, write your own: int strcicmp(char const *a, char const *b) { for (;; a++, b++) { int d = tolower((unsigned char)*a) -

What is purpose of the div() library function?

你说的曾经没有我的故事 提交于 2019-11-27 02:23:41
When c has the / operator to divide two numbers, what is the purpose of having the div() library function ? Is there any scenario where / can't be used but div() can? From the C99 Rationale document: (7.20.6.2 The div, ldiv, and lldiv functions) Because C89 had implementation-defined semantics for division of signed integers when negative operands were involved, div and ldiv, and lldiv in C99, were invented to provide well-specified semantics for signed integer division and remainder operations. The semantics were adopted to be the same as in Fortran. Since these functions return both the

stdio.h not standard in C++?

孤人 提交于 2019-11-27 01:52:06
I know most compilers allow both: #include <stdio.h> //and #include <cstdio> But someone argued that <stdio.h> is not actually C++ standard. is that true? stdio.h is standard, but deprecated. Always prefer cstdio in C++. [n3290: C.3.1/1]: For compatibility with the Standard C library, the C++ standard library provides the 18 C headers (D.5), but their use is deprecated in C++. [n3290: D.5/3]: [ Example: The header <cstdlib> assuredly provides its declarations and definitions within the namespace std . It may also provide these names within the global namespace. The header <stdlib.h> assuredly

Which functions in the C standard library commonly encourage bad practice? [closed]

别等时光非礼了梦想. 提交于 2019-11-26 23:51:20
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . This is inspired by this question and the comments on one particular answer in that I learnt that strncpy is not a very safe string handling function in C and that it pads zeros, until it reaches n , something I was unaware of. Specifically, to quote R.. strncpy does not null

When is #include <new> library required in C++?

六眼飞鱼酱① 提交于 2019-11-26 22:42:51
问题 According to this reference entry for operator new ( http://www.cplusplus.com/reference/std/new/operator%20new/ ) : Global dynamic storage operator functions are special in the standard library: All three versions of operator new are declared in the global namespace, not in the std namespace. The first and second versions are implicitly declared in every translation unit of a C++ program: The header does not need to be included for them to be present. This seems to me to imply that the third

Swift's standard library and name collision

烂漫一生 提交于 2019-11-26 21:47:26
问题 I know that Swift doesn't use namespaces, but that names are defined within each module. First of all, I don't understand very well how this avoids name collisions -feel free to elaborate. Nevertheless, my main question is: Let's say I want a tree structure without using NSTreeNode, so I make my own class named "TreeNode". Now let's say that Apple decides to include a class to build trees in Swift's standard library, and, as expected, they name it "TreeNode". What happens then? My custom

Does std::mt19937 require warmup?

落爺英雄遲暮 提交于 2019-11-26 21:40:56
I've read that many pseudo-random number generators require many samples in ordered to be "warmed up". Is that the case when using std::random_device to seed std::mt19937, or can we expect that it's ready after construction? The code in question: #include <random> std::random_device rd; std::mt19937 gen(rd()); bames53 Mersenne Twister is a shift-register based pRNG (pseudo-random number generator) and is therefore subject to bad seeds with long runs of 0s or 1s that lead to relatively predictable results until the internal state is mixed up enough. However the constructor which takes a single

Getting a machine's external IP address with Python

别等时光非礼了梦想. 提交于 2019-11-26 21:30:29
Looking for a better way to get a machines current external IP #... Below works, but would rather not rely on an outside site to gather the information ... I am restricted to using standard Python 2.5.1 libraries bundled with Mac OS X 10.5.x import os import urllib2 def check_in(): fqn = os.uname()[1] ext_ip = urllib2.urlopen('http://whatismyip.org').read() print ("Asset: %s " % fqn, "Checking in from IP#: %s " % ext_ip) Sunny Milenov If you are behind a router which obtains the external IP, I'm afraid you have no other option but to use external service like you do. If the router itself has

Why do some built-in Python functions only have pass?

一个人想着一个人 提交于 2019-11-26 20:45:48
I wanted to see how a math.py function was implemented, but when I opened the file in PyCharm I found that all the functions are empty and there is a simple pass . For example: def ceil(x): # real signature unknown; restored from __doc__ """ ceil(x) Return the ceiling of x as a float. This is the smallest integral value >= x. """ pass I guess it is because the functions being used are actually from the C standard library. How does it work? PyCharm is lying to you. The source code you're looking at is a fake that PyCharm has created. PyCharm knows what functions should be there, and it can