Posts Tagged ‘programming’

GCC — 64bits addressing: function returns 32bits pointer

Today, it was the second time I stepped on an interesting problem with GCC  (well, it is actually a behavior). I created a function which returns a void* in a .c file. This C file was then compiled and added in a library (.a). When I used this function in an application, I was getting a void* pointer were the 32 most significant bits were either zeroed (0x00000000...) or set to 1 (0xFFFFFFFF...). My application is 64bit!!

For example, the debug prints I added would return:

[lib] allocated 0x7f756d6fa048
[app] allocated 0x6d6fa048

where you can see the “conversion”.

What was the problem? After some time of debugging, I realized that I had forgotten to include the aforementioned function in the corresponding header file :|. So, although GCC could find the function in the library I was linking the application to, I guess it was assuming a wrong return value/header for that function.

The conclusion: Be more careful 😉

PS. I am using the following version of GCC:

$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' 
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ 
--prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib 
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix 
--with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ 
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes 
--enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror 
--with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

Top 25 Most Dangerous Software Errors

The 2011 CWE/SANS Top 25 Most Dangerous Software Errors is a list of the most widespread and critical errors that can lead to serious vulnerabilities in software. They are often easy to find, and easy to exploit. They are dangerous because they will frequently allow attackers to completely take over the software, steal data, or prevent the software from working at all.

The Top 25 list is a tool for education and awareness to help programmers to prevent the kinds of vulnerabilities that plague the software industry, by identifying and avoiding all-too-common mistakes that occur before software is even shipped. Software customers can use the same list to help them to ask for more secure software. Researchers in software security can use the Top 25 to focus on a narrow but important subset of all known security weaknesses. Finally, software managers and CIOs can use the Top 25 list as a measuring stick of progress in their efforts to secure their software.

Find the list here.

Introduction to Erlang : Installing Erlang

This entry is part 2 of 16 in the series Introduction to Erlang

About Erlang

Erlang is a functional programming language which has many features more commonly associated with an operating system than with a programming language: concurrent processes, scheduling, memory management, distribution, networking, etc.

The initial open-source Erlang release contains the implementation of Erlang, as well as a large part of Ericsson’s middleware for building distributed high-availability systems.
Read the rest of this entry »

Introduction to Erlang post series

This entry is part 1 of 16 in the series Introduction to Erlang

While I was writing my first actual (and extremely delayed :-S) article for the Parallelizing simple algorithms series, I realized that since Erlang is not a popular programming language it would be nice to start an Introduction to Erlang post series. I consider Erlang as a must-know language for an engineer that works with distributed systems and parallel programming. Believe me, in several cases, Erlang is a problem solver!

I will try to keep the posts short and example based. An approximation of the posts that I intend to write is:

  1. Basics: how to get a working Erlang environemt
  2. Basic Types: integers, floats, …
  3. Modules and Compiling: how to write and compile a module
  4. Functions: how to delcare functions
  5. Library Functions & BIFs
  6. Lists: list manipulation
  7. Processes: how to create new processes
  8. Message Passing: how to send messages between processes
  9. Debugging: how to debug Erlang programms
  10. Records: how to use records

I will keep this list updated in case that I come up with new ideas!

I hope I will convince you that Erlang worths every software engineer’s attention..

Parallelizing simple algorithms : Fibonacci

This entry is part 2 of 2 in the series Parallelizing simple algorithms
Fibonacci Blocks

Fibonacci Blocks

It took me a little more than I expected, but finally I managed to write the first post for the Parallelizing simple algorithms series.

As I “promised”, I will start these series by parallelizing the Fibonacci Number sequence generation. As you probably already know, Fibonacci numbers are the integer sequence produced by the following relationship:

   F0 = 0
   F1 = 1
   Fn = Fn-2 + Fn-1

The resulting sequence is: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, . . .

Lets start with programming!

Read the rest of this entry »

Pointers and Arrays in C

As anyone who had programmed in C knows, pointers can be (also) used to access the data of an array.

From the Wikipedia article about C language:

C supports the use of pointers, a very simple type of reference that records, in effect, the address or location of an object or function in memory. Pointers can be dereferenced to access data stored at the address pointed to, or to invoke a pointed-to function. Pointers can be manipulated using assignment and also pointer arithmetic. The run-time representation of a pointer value is typically a raw memory address (perhaps augmented by an offset-within-word field), but since a pointer’s type includes the type of the thing pointed to, expressions including pointers can be type-checked at compile time. Pointer arithmetic is automatically scaled by the size of the pointed-to data type.

Read the rest of this entry »

Parallelizing simple algorithms series

This entry is part 1 of 2 in the series Parallelizing simple algorithms
Fibonacci Spiral

Fibonacci Spiral

In the following weeks, I will try to write some posts about parallelizing simple algorithms with the Erlang programming language. The main motivation for executing program instructions in parallel is to complete the computation faster than the sequential equivalent solution. As it is used, when someone wants to present the “parallelization power” of a programming language/model, the Fibonacci numbers are used. So, following this conversion, my first post will be about parallelizing the calculation of the Fibonacci integer sequence.
Read the rest of this entry »