Strainu onLine
Blogul unui automatist
15th
MAY
A little fun with cdecl
Posted by Strainu | Filed under C
One of my teachers decided one day that he should write a pointer to an array of functions receiving a pointer to a function receiving an int and returning a pointer to a function receiving an array of pointers to int and returning int and an int and returning a pointer to a function receiving a pointer to a function receiving a pointer to an array of int and an int and returning a pointer to int and returning a function receiving int and returning int.
Fun, huh?
Let’s try one more time:
a pointer to an array of functions | receiving a pointer to a function | | receiving an int | | returning a pointer to a function | | | receiving an array of pointer to int | | | returning int | an int | returning a pointer to a function | | receiving a pointer to a function | | | receiving a pointer to an array of int | | | an int | | | returning a pointer to int | | returning a function | | | receiving int | | | returning int
It does sounded quite tricky to me. Still, he managed to write it down in just 10 minutes. The secret? Cdecl. Cdecl reads files for statements which should be translated to C or C++. Six different statement are supported: declare composes a C type-declaration, cast composes a C type-cast, and so on. The grammar is described in full in the man page.
And here is the result for the function described above:
8th
MAY
How to read the bits in a IEEE 754 number?
Posted by Strainu | Filed under C
That’s one of those questions you always wanted to know the answer to, but never found somebody who knew, right?
Well, in C it’s pretty simple. All you have to do is to declare an union, like this:
float f;
int bits;
}
This tells the compiler that both f and bits should be hold in the same memory zone. This is pretty useful to save some memory, if you know for sure that you wown’t need f and bits in the same time.
As a side effect, if you write a value in f then read bits, you will have all the bits represented in the IEEE 754 standard. Now you can use bit operations (& , | , ^) with your number, you can extract the different parts of the number, etc. Do keep in mind that this is bad programming practice.
4th
MAY
Macros using do{}while(0);
Posted by Strainu | Filed under C
If you ever had the chance to look in the Linux kernel sources, you might have seen macros defined like this:
do{ \
//instructions \
}while(0)
This basicly means that the code is executed exactly once, so the first idea is that do{}while(0); is useless.
In fact, there are a number of reasons for writing the macros this way:
- Empty statements give warnings from the compilers, so rather than writing
#define FOO
you might want to write
#define FOO do{}while(0) - It gives you a basic block in which to declare local variables. You could simply use curly brackets, but this could cause serious problems in conditional statements. Let’s take the following example:
#define exch(a,b) {int t; t = a; a = b; b = t;}
You then use the macro in the following code:
if(a[i]<a [i+1])
exch(a[i],a[i+1]);
else
ready = 1;This is what the copiler will get:
if(a[i]<a [i+1]){
int t;
t = a[i];
a[i] = a[i+1];
a[i+1] = t;
};
else
ready = 1;This is interpreted as an if statement whithout else and you will get an error like “else without matching if”. However, if you write the macro like this:
#define exch(a,b) do{int t; t = a; a = b; b = t;}while(0)the code will behave as expected.
You can find more informations about this in the Kernelnewbies FAQ.
1st
MAY
Zero-extent array members
Posted by Strainu | Filed under C
Some compilers, such as GCC or IBM’s compiler have a C extension that allows for a zero-extent array members of a structure to be declared:
//other members
char data[0];
};
They are very useful if you have a structure for a variable-length object. Until they are allocated the zero-extent members will not take up any memmory. When you have to allocate memory for such a structure, you can do it this way:
struct inode *ind = (struct inode*) malloc(sizeof(struct inode) + size_of_the_array);
You have to keep in mind that this is a language extension. The C99 standard only allows flexible array members, which are defined as
char array[];
(without the 0) and behave somewhat differently. You can find out more about the subject in the GCC Manual.
30th
JAN
Operating Systems homeworks
Posted by Strainu | Filed under C, Software
Operating Systems homeworks from the Automatics and Computer Science Faculty, 4th year, prof. Marius Dorian Zaharia. Themes:
- using Linux;
- bash;
- processes and threads in Linux;
- IPC: semaphores, message queues, signals, shared memory;
- readers-writers, producers-consumers and philosopher’s problems.
Tags: C/C++, Linux, Operating Systems, Poli, Software
24th
AUG
Digital/analogue clock
Posted by Strainu | Filed under C++, Software

Digital/analogue clock A DevC++ program that shows an analogue or digital clock. The program shows the usage of classes in C++ and the usage of Windows drawing functions.
(more…)
12th
JUL
Networking Protocols homeworks
Posted by Strainu | Filed under C, Software
Networking Protocols homeworks Networking Protocols homeworks, Automatics and Computer Science Faculty, UPB, 3rd year, prof. Florin Pop or Valentin Cristea.
The software is distributed under CC-GNU GPL license.
23rd
JUN
BlackJack (21)
Posted by Strainu | Filed under C++, Software

BlackJack (21) is a simple simulation of a Black Jack game. Is shows the usage of bitmaps as background for MFC applications.
(more…)
23rd
ThePlayZone
Posted by Strainu | Filed under C++, Software

ThePlayZone is a simple mp3 player. It can read ID3v1 tags, the bitrate and frequency, and play m3u and pls playlists.
(more…)
29th
MAR
Algorithm Analysis Labs
Posted by Strainu | Filed under C, Software
Algorithm Analysis Labs (sorting methods and graph labs), Automatics and Computer Science Faculty, UPB, 3rd year, prof. Cristian Giumale
The software is distributed under CC-GNU GPL license.
Tags: Algorithm Analysis, C/C++, Poli, Software
Recent Posts:
- 28 Oct Some people just won̵...
- 18 Aug Wiki Loves Monuments RomÃ...
- 15 May Want to work on Pidgin or...
- 14 Apr Free WiFi in the metro!
- 04 Apr Libertatea dincolo de sof...
- 11 Feb Electrocasnice online: Do...
- 15 Oct Wikipedia română –...
- 14 Oct Veliko Tarnovo Sound ...
- 11 Oct Romanian Postal Codes in ...
- 11 Jul Wikimania 2010 – zi...






