Skip to main content

Posts

Showing posts with the label c++

What is ":-!!' in C code?

I bumped into this strange macro code in /usr/include/linux/kernel.h : /* Force a compilation error if condition is true, but also produce a result (of value 0 and type size_t), so the expression can be used e.g. in a structure initializer (or where-ever else comma expressions aren't permitted). */ #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))

How much to grow buffer in a StringBuilder-like C module?

In C, I'm working on a "class" that manages a byte buffer, allowing arbitrary data to be appended to the end. I'm now looking into automatic resizing as the underlying array fills up using calls to realloc . This should make sense to anyone who's ever used Java or C# StringBuilder . I understand how to go about the resizing. But does anyone have any suggestions, with rationale provided, on how much to grow the buffer with each resize?

What are the benefits (and drawbacks) of a weakly typed language?

I'm a big fan of PHP and it's obviously a very weakly-typed language. I realize some of the benefits include the general independence of changing variable types on the fly and such. What I'm wondering about are the drawbacks. What can you get out of a strongly-typed language like C that you otherwise can't get from a weakly-typed one like PHP? Also with type setting (like double($variable)), one could argue that even a weakly-typed language can act just like a strongly-typed one. So. Weak-type. What are some benefits I didn't include? More importantly, what are the drawbacks? Source: Tips4all

iPhone ResetCounter Crash

I have write a native c executable program and run it on iPhone4. First, it works well, but after a period of time, it will cause iphone reboot every time when I run it. There is a Crash Report in /var/logs/CrashReporter, name is ResetCounter-2012-02-23-203134.plist. Can any body tell me what is happend? Thank you. <?xml version="2.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>AutoSubmitted</key> <true/> <key>SysInfoCrashReporterKey</key> <string>18a43ae69755297d4e14405a1f7b7a8119557668</string> <key>bug_type</key> <string>115</string> <key>description</key> <string>Incident Identifier: B7F9154E-C607-4706-AF42-0FF04594114B CrashReporter Key: 18a43ae69755297d4e14405a1f7b7a8119557668 Da