Quantcast
Browsing latest articles
Browse All 40 View Live

Comment by Nicholas Knight on When printf is an address of a variable, why...

@Blindy: No, they are not. Different 64-bit platforms won't even behave the same. See, for example, en.wikipedia.org/wiki/64-bit#64-bit_data_models

View Article


Comment by Nicholas Knight on 2+2=2 in C (double arithmetics)

Your question has been answered, but you also have another error. You're including stdlib.h, but printf and scanf are not defined in stdlib.h. You need stdio.h. By the way, your compiler really ought...

View Article


Comment by Nicholas Knight on Python remove JSON substring

What isn't Python 3-compliant about find and rfind?

View Article

Comment by Nicholas Knight on What is the C++ equivalent for AutoResetEvent...

@derekhh: I don't know about "easier", condition variables are a fairly simple construct, but if you're already using boost::thread (which IMO is a perfectly good choice), by all means use its...

View Article

Comment by Nicholas Knight on Efficient structure for element wise access to...

I might be missing something, but why are you keying the dict with strings like that? (i,j) is a perfectly valid dict key.

View Article


Comment by Nicholas Knight on Unable to use cout with a C++ string unless I...

What is in "more code here"? I suspect it's significant.

View Article

Comment by Nicholas Knight on Git clone failing on public key. Is there...

AJP, I've removed the "explicit solution" you edited into Amber's answer. Even if, for some unfathomable reason, you're OK with your projects directory being world-readable-and-writable, leaving a...

View Article

Comment by Nicholas Knight on Why does a read(2) call on Linux spend several...

Note that gettimeofday isn't the best way to do performance timings, it's subject to clock changes from e.g. ntpd. See stackoverflow.com/questions/88/…

View Article


Comment by Nicholas Knight on Are extended instruction sets (SSE, MMX) used...

@us2012 That's probably a very bad idea if for no other reason than that the kernel isn't designed for it, and you may unexpectedly clobber user-space SIMD register values (or user-space may clobber...

View Article


Comment by Nicholas Knight on How many keys are too many in memcached?

@user1130176 Not in the average case, no. O(log(n)) behavior from a putative hash table would suggest a broken or misapplied implementation. You may be thinking of some other structure also commonly...

View Article

Comment by Nicholas Knight on Go: test internal functions

@George I don't know where you got the idea testing your internals is an anti-pattern, but you should never, ever take advice from that source again. Yes, testing your external API is important, but...

View Article

Answer by Nicholas Knight for How safe is the apple binary (secret key saftey)

The binary is not even remotely safe. Whether through the iTunes download or on a jailbroken iPhone, there's nothing you can do other than obfuscation, which a determined adversary will always get...

View Article

Answer by Nicholas Knight for pydev - can someone please explain these errors

Neil speaks the truth, except for telling you to turn it off -- spell check in comments is quite helpful -- those who come after will thank you for ensuring they can read your comments without trying...

View Article


Answer by Nicholas Knight for Using Version Control but still access the...

You need a deployment script. Create a script to upload the files to the appropriate locations. Run this script whenever you wish to see your changes reflected on the site. If you wish to maintain two...

View Article

Answer by Nicholas Knight for Free 64-bit disassembler?

GNU binutils has objdump, which should work:-d--disassembleDisplay the assembler mnemonics for the machine instructions from objfile. This option only disassembles those sections which are expected to...

View Article


Answer by Nicholas Knight for Xcode 4 C++ header file with relative path to...

Don't use relative paths. Seriously, it's implementation-defined behavior how they work, so different compilers/environments/platforms will behave differently, and in your case, Xcode is almost...

View Article

Answer by Nicholas Knight for Can XNA games run on mac?

The short answer: Yes, in theory, but don't expect perfection, at least not right off the bat. You'd probably have some work ahead of you to get a good experience.MonoXNA is just an open-source...

View Article


Answer by Nicholas Knight for PHP mkdir: 0777 becomes 0755?

Your umask is probably set to 0022 (a common default), preventing the write bits from being set for group and other. You can use the umask function to change the current umask.But then, why are you...

View Article

Answer by Nicholas Knight for Most stable gcc/g++ version to date

The 2.95 branch hasn't had an update in over ten years. I certainly wouldn't be using it for anything voluntarily. Use whatever is the latest available for your system unless you have specific...

View Article

Answer by Nicholas Knight for By default, does gcc link to static or dynamic...

It is technically system dependent, but on most systems you're likely to develop for, the answer is "dynamic".A few systems (mostly very old, embedded, or otherwise specialized) do not support dynamic...

View Article

Answer by Nicholas Knight for Can you link a C++ library from a C application?

The easiest, least-hassle method to do this, assuming your C code is reasonably sane, is to simply build your C application with g++.Remember, good C code almost always builds in a C++ compiler. Then...

View Article


Answer by Nicholas Knight for When printf is an address of a variable, why...

So much insanity present here...%p is generally the correct format specifier to use if you just want to print out a representation of the pointer. Never, ever use %d.The length of an int and the length...

View Article


Answer by Nicholas Knight for How does C code call assembly code (e.g....

Many (most?) C compilers do happen to support inline assembly, though it's not part of the standard. That said, there's no strict need for a compiler to support any such thing.First, recognize that...

View Article

Answer by Nicholas Knight for Getting an embedded Python runtime to use the...

Well, the C API docs kind of imply it should just work (I read it as vaguely hinting the interpreter calls getenv itself), but seem to lack sufficient context to be certain, and I've never had occasion...

View Article

Answer by Nicholas Knight for Can I keep threads alive and give them other...

The usual, simple form is an ordinary (work) queue. In principle, you maintain a queue structure, perhaps as a linked list, protected by a mutex. Typically, condition variables are used by the...

View Article


Answer by Nicholas Knight for How to check exit if used tee?

For bash, there's a convenient special array: PIPESTATUS. The return code for myapp would be in ${PIPESTATUS[0]} and so on.zsh has a roughly identical method.There's also a rather more annoying, hacky...

View Article

Why does argparse give me a list-in-a-list?

I just noticed a behavior in argparse that puzzled me (guess I'd never used it for a dumb list of files before):import argparseparser = argparse.ArgumentParser()parser.add_argument('multi',...

View Article

Answer by Nicholas Knight for Default GCC flags

The only two options there that make any sense to override are -D_FORTIFY_SOURCE and -fstack-protector, so just include -U_FORTIFY_SOURCE and -fnostack-protector, and they're effectively "gone".You...

View Article

Answer by Nicholas Knight for posix threads (pthreads) standard

Yes, that's a very old document. What you probably want is the full POSIX 2008 spec.

View Article



Answer by Nicholas Knight for Why doesn't the Go statement execute in parallel?

You probably need to review the Concurrency section of the Go FAQ, specifically these two questions, and work out which (if not both) apply to your case:Why doesn't my multi-goroutine program use...

View Article

What does "evaluated only once" mean for chained comparisons in Python?

A friend brought this to my attention, and after I pointed out an oddity, we're both confused.Python's docs, say, and have said since at least 2.5.1 (haven't checked further back:Comparisons can be...

View Article

Answer by Nicholas Knight for Should I use \d or [0-9] to match digits in a...

For maximum safety, I'd suggest using [0-9] any time you don't specifically intend to match all unicode-defined digits.Per perldoc perluniintro, Perl does not support using digits other than [0-9] as...

View Article

Can I recursively create a path in Zookeeper?

I'm pulling ZooKeeper into a project for some concurrency management, and the first thing I tried was something that, to me, was quite obvious (using the zkpython binding):zh =...

View Article


Answer by Nicholas Knight for Why use argparse rather than optparse?

As of python 2.7, optparse is deprecated, and will hopefully go away in the future.argparse is better for all the reasons listed on its original page...

View Article

Answer by Nicholas Knight for Printf security golang

tl;dr: Don't print untrusted data, escape it first. If in doubt or a hurry, use %q instead of %s.Go's string formatting methods are, indeed, memory-safe, and the specific class of vulnerabilities...

View Article

Answer by Nicholas Knight for How to validate an Email address in Django?

Ick, no, please, don't try to validate email addresses yourself. It's one of those things people never get right.Your safest option, since you're already using Django, is to just take advantage of its...

View Article


Answer by Nicholas Knight for Create a list from a long int

It's not exactly clear what you're asking for, but if what you want is to iterate over the digits, just convert it to a string:x = str(n)You can iterate over a string as if it were a list.If you really...

View Article


Answer by Nicholas Knight for Can read(2) return zero when not at EOF?

After some research, there actually are some circumstances under which it will return 0 that you might not think of as being "EOF".For the gritty details, see the POSIX definition for read():...

View Article

Answer by Nicholas Knight for Encoding nested python object in JSON

So, the immediate problem is that you're passing the json module a JSON value, which will get encoded as just another string in the JSON value.The broader problem is that you're greatly...

View Article
Browsing latest articles
Browse All 40 View Live