Showing posts with label c++. Show all posts
Showing posts with label c++. Show all posts

Monday, June 11, 2012

What is the purpose of a these #define within an enum?


I found this code in the linux headers, /usr/include/dirent.h:




enum
{
DT_UNKNOWN = 0,
# define DT_UNKNOWN DT_UNKNOWN
DT_FIFO = 1,
# define DT_FIFO DT_FIFO
DT_CHR = 2,
# define DT_CHR DT_CHR
DT_DIR = 4,
# define DT_DIR DT_DIR
DT_BLK = 6,
# define DT_BLK DT_BLK
DT_REG = 8,
# define DT_REG DT_REG
DT_LNK = 10,
# define DT_LNK DT_LNK
DT_SOCK = 12,
# define DT_SOCK DT_SOCK
DT_WHT = 14
# define DT_WHT DT_WHT
};

C++ versus D


Is the D language a credible alternative to Java and C++? What will it take to become a credible alternative? Should I bother learning it? Does it deserve evangelizing?

Sunday, June 10, 2012

Sunday, June 3, 2012

How to get 100% CPU usage from a C program


This is quite an interesting question so let me set the scene. I work at The National Museum of Computing, and we have just managed to get a Cray Y-MP EL super computer from 1992 running, and we really want to see how fast it can go!

Friday, June 1, 2012

Finding current executable"s path without /proc/self/exe


It seems to me that Linux has it easy with /proc/self/exe. But I'd like to know if there is a convenient way to find the current application's directory in C/C++ with cross-platform interfaces. I've seen some projects mucking around with argv[0], but it doesn't seem entirely reliable.

Write applications in C or C++ for Android?


I'm trying to develop/port a game to Android, but it's in C, and Android supports Java, but I'm sure there must be a way to get a C app on there, anyone knows of a good tutorial on the subject?

Tuesday, May 29, 2012

Sunday, May 27, 2012

Is it safe to parse a /proc/ file?


Well, this is going to be a short one...



I want to parse /proc/net/tcp/ , but is it safe? I mean, how to open and read it and not be afraid, that some other process (or the OS) will be changing it in the same time?

Friday, May 25, 2012

Vim and Ctags tips and tricks


I have just installed Ctags (to help with C++ development) with my Vim (or rather gVim), and would like to find out your favorite commands, macros, shortcuts, tips that go along with it...

Thursday, May 24, 2012

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); }))

Wednesday, May 23, 2012

What is the LD_PRELOAD trick?


I came across a reference to it recently on proggit and (as of now) it is not explained.

Friday, May 18, 2012

Why main does not return 0 here?


I was just reading



ISO/IEC 9899:201x Committee Draft — April 12, 2011

Very small programs to improve programming skills?


I realize that to become a better programmer, you need to program! So obviously the more practice, the better you become.

Thursday, May 17, 2012

Vim and Ctags tips and tricks


I have just installed Ctags (to help with C++ development) with my Vim (or rather gVim), and would like to find out your favorite commands, macros, shortcuts, tips that go along with it...

Wednesday, May 16, 2012

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?

Tuesday, May 15, 2012

Friday, April 27, 2012

Objective-C: unichar vs. char


I'm a little confused between a unichar and a char. Can I treat unichar's similar to char's?

Wednesday, April 25, 2012

Which complements Python best: Java, C, or C++?


I am in the process of applying to a Computer Science program which requires students to have at least an intro-level exposure to either Java, C or C++. I have some experience with Python and I would prefer to continue working in Python before starting another language; however, the professor said that Python was too light, i.e. "it's just a scripting language, you need to know a more robust language".

Monday, April 23, 2012

How can i do speech recognition in C or Java or PHP?


Is there any well known established framework for C or Java or PHP to do speech recognition applications? Microphone audio input and it will recognize English words. Such as pseudo code:

Friday, April 6, 2012

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.