
Simply one of the most useful websites I have come across in recent time. It is a resource to find the open source alternatives to commercial software.
Experiences, Adventures, Appreciations, Notes, Tips, Tricks and References on using Ubuntu (sometimes Linux in general).
A 32-bit operating system is limited to 4 GB of memory ( you can only reference 2 ^ 32 = 4GB ). However, 32-bit Ubuntu is limited to 3 GB. If you are considering between 32-bit and 64-bit Ubuntu and you have more than 3 GB of memory that should be a simple decision.
There is a workaround however if you are still not convinced 64-bit is the way to go - install server kernel as it has support for upto 4 GB. But think about the future when your 4GB will not be enough and you add more memory?
When using inheritance, destructors are called in the reverse order of inheritance. If a base class pointer points to a derived class object, and later we use the delete operator to delete the object, then the derived class destructor is not called. Refer to the code that follows:
#include
class base
{
public:
~base()
{
}
};
class derived : public base
{
public:
~derived()
{
}
};
void main()
{
base *ptr = new derived();
// some code
delete ptr;
}
The result is a memory leak.
Solution to avoid this -
Make the destructor virtual in the base class. A virtual destructor is one that is declared as virtual in the base class.
#include
class base
{
public:
virtual ~base()
{
}
};
class derived : public base
{
public:
~derived()
{
}
};
void main()
{
base *ptr = new derived();
// some code
delete ptr;
}
Does this mean when using virtual functions, it is always a good idea have the destructor virtual as well?
Each ELF file is made up of one ELF header, followed by file data. The file data can include:
readelf
is a Unix binary utility that displays information about one or more ELF files.objdump
provides a wide range of information about ELF files and other object formats.
rutul@ubuntu:~/test_progs$ gcc hello_world.c
rutul@ubuntu:~/test_progs$ ldd a.out
linux-gate.so.1 => (0xb7ef2000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7d80000)
/lib/ld-linux.so.2 (0xb7ef3000)
rutul@ubuntu:~/test_progs$
rutul@ubuntu:~/test_progs$ readelf -l a.out
Elf file type is EXEC (Executable file)
Entry point 0x8048310
There are 8 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x08048034 0x08048034 0x00100 0x00100 R E 0x4
INTERP 0x000134 0x08048134 0x08048134 0x00013 0x00013 R 0x1
[Requesting program interpreter: /lib/ld-linux.so.2]
LOAD 0x000000 0x08048000 0x08048000 0x004c4 0x004c4 R E 0x1000
LOAD 0x000f0c 0x08049f0c 0x08049f0c 0x00108 0x00110 RW 0x1000
DYNAMIC 0x000f20 0x08049f20 0x08049f20 0x000d0 0x000d0 RW 0x4
NOTE 0x000148 0x08048148 0x08048148 0x00020 0x00020 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
GNU_RELRO 0x000f0c 0x08049f0c 0x08049f0c 0x000f4 0x000f4 R 0x1
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.ABI-tag .hash .gnu.hash .dynsym .dynstr .gnu.version .gn
u.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame
03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss
04 .dynamic
05 .note.ABI-tag
06
07 .ctors .dtors .jcr .dynamic .got
rutul@ubuntu:~/test_progs$
#include
int main()
{
int for_a = 100;
int for_b = 200;
int for_test = 300;
const int* a = &for_a;
int* const b = &for_b;
a++; // allowed
a--;
// *a = for_test; // not allowed: "assignment of read-only location"
// b++; // not allowed: "increment of read-only variable"
*b = for_test; // allowed
printf("Value of *a = %d, value of *b = %d \n", *a, *b);
return 1;
}
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.3 LTS"
#cat /etc/redhat-release
$ cat /etc/SuSE-release
openSUSE 11.1 (i586)
VERSION = 11.1
mcelog decodes machine check events (hardware errors) on x86-64 machines running a 64-bit Linux kernel. It should be run regularly as a cron job on any x86-64 Linux system (if it is not in the default packages on your x86-64 distribution, please complain to your distributor). It can also decode machine check panic messages from console logs.I don't have a good example on it´s usage, but on one of my systems, I noticed this in /var/log/mcelog (the cron script is setup to write to /var/log/mcelog in Fedora distributions).
You must post your business plan here on my blog where I expect other people can and will comment on it. I also expect that other people will steal the idea and use it elsewhere. That is the idea. Call this an open source funding environment.
foo.hOne more reason why I don't consider myself a C++ programmer.
class bar {
public:
int getBar1();
private:
static int bar1;
};
foo.cpp
#include "foo.h"
int bar::bar1;
.....
....