Here, some useful tips or unknowns of C/C++ programming are listed for further reference:
1. Stand alone curly brackets in code.
Sometimes a pair of curly brackets can be found in a C/C++ code file. It seems to be useless:
Configurator::only ().dump();
{
strbuf x = strbuf ("starting: ");
for (int i = 0; i < argc; i++) {
x << argv[i] << " ";
}
x << "\n";
info << x;
}
Here, the curly brackets is not necessarily to exist. However, they have their meanings from two different point of views: Scope perspective and Legacy perspective.
In scope perspective, the codes in the pair of curly brackets is in a new sub scope.
In legacy perspective, the legacy C standard needs variable declarations to be in the very front of the code. The curly brackets are able to make a new "beginning".
I am working on a C++ project. So the original coder considered in a scope perspective.
Saturday, 23 March 2013
Monday, 22 October 2012
How to use and tweak Emacs Code Browser
Emacs is one of the most featured text editor in Linux/Unix like systems. The users don't need to move over the fingers to achieve almost all operations to edit text files or to code. It would be a quite efficient multi-function text editor if the horrible beginning start time of using it is neglected. Some keyboard companies produce specific customised keyboard such as HHKB for the ease of Emacs' using.
One of the Emacs' feature is to browser a program project with a large number of source files. More windows and tools are provided to navigate through the whole project. However, the installation and settings of ECB (Emacs Code Browser) is very complicated with a lot of works involved in its long manual. Here I record my short settings of a usable ECB. Not all of the features of either Emacs or ECB are exploited according to my settings, because I am also a newbie of Emacs and ECB. All of my efforts contribute on the usable version of working Emacs and ECB.
Setting the ECB to work in Emacs.
Find out the location of the installed ECB. I installed it by using yum tools. In this case, the location is /usr/share/emacs/site-lisp/ecb. Put this path into the list of emacs' load-path. Then require the ecb after that. However, an error message would be shown up saying that something wrong with the stack-trace-on-error. Then toggle on the stack-trace-on-error before load the ecb to the load-path in .emacs, the configuration file of Emacs.
ECB would ask you to insert some other setting to Emacs' configuration file. Just accept it is fine.
How to use the ECB:
1. navigation among different windows:
use the C-c . g (x) command, where (x) can be:
d: directory window
s: source files window
m: class and function names window
h: history window
2. Show any working directory in directory window.
When I open the ECB mode by using M-x ecb-activate, the directory window have nothing displayed. In order to set the working directory in the directory window the following steps are required:
M-x customize-option RET ecb-source-path RET
Choose the INS button in the opening custom buffer in order to insert a directory as a source path.
Choose to save for current session or for future sessions by type a number for specific type saving. Then the working directory should be shown in the directory window.
3. Customise the layout of ECB
There are several predefined layout available to users in ECB. The method used to change to these layouts is to set the option "ecb-layout-name". This is quite similar with the method used to set the working path of current session. The local tool of Emacs: M-x customize-option is employed to accomplish these sort of tasks.
The command M-x ecb-show-layout-help can be used to check the details of a predefined layout through it text-type picture.
One of the Emacs' feature is to browser a program project with a large number of source files. More windows and tools are provided to navigate through the whole project. However, the installation and settings of ECB (Emacs Code Browser) is very complicated with a lot of works involved in its long manual. Here I record my short settings of a usable ECB. Not all of the features of either Emacs or ECB are exploited according to my settings, because I am also a newbie of Emacs and ECB. All of my efforts contribute on the usable version of working Emacs and ECB.
Setting the ECB to work in Emacs.
Find out the location of the installed ECB. I installed it by using yum tools. In this case, the location is /usr/share/emacs/site-lisp/ecb. Put this path into the list of emacs' load-path. Then require the ecb after that. However, an error message would be shown up saying that something wrong with the stack-trace-on-error. Then toggle on the stack-trace-on-error before load the ecb to the load-path in .emacs, the configuration file of Emacs.
ECB would ask you to insert some other setting to Emacs' configuration file. Just accept it is fine.
How to use the ECB:
1. navigation among different windows:
use the C-c . g (x) command, where (x) can be:
d: directory window
s: source files window
m: class and function names window
h: history window
2. Show any working directory in directory window.
When I open the ECB mode by using M-x ecb-activate, the directory window have nothing displayed. In order to set the working directory in the directory window the following steps are required:
M-x customize-option RET ecb-source-path RET
Choose the INS button in the opening custom buffer in order to insert a directory as a source path.
Choose to save for current session or for future sessions by type a number for specific type saving. Then the working directory should be shown in the directory window.
3. Customise the layout of ECB
There are several predefined layout available to users in ECB. The method used to change to these layouts is to set the option "ecb-layout-name". This is quite similar with the method used to set the working path of current session. The local tool of Emacs: M-x customize-option is employed to accomplish these sort of tasks.
The command M-x ecb-show-layout-help can be used to check the details of a predefined layout through it text-type picture.
Sunday, 21 October 2012
Thread-local storage
Thread-local storage (TLS) is a programming method that is used to make static and global variables be local to a thread. The '"errno" is a canonical example of TLS method. Actually, a "errno" should be a static variable used by all functions to determine the error status. However, in each thread of a running process, there should be a separated one in order to prevent the infection from other threads in the same process.
The comparing method to achieve the similar function with the TLS is the thread lock for a static or global variable. However, a carelessness of requiring the lock in any threads in the process would affect other threads.
The comparing method to achieve the similar function with the TLS is the thread lock for a static or global variable. However, a carelessness of requiring the lock in any threads in the process would affect other threads.
Saturday, 1 September 2012
Code counting program
For some reasons, I just want to count the number of lines of code which I have already completed locally. There are several methods to achieve this task, such as the Doxygen and the Git tools. They can all produce a rather good report on the program's physical statistics, for example the lines of code. What I was looking for, however, is a lightweight solution which could only count the number of code lines.
SLOCCount is just this kind of tool which is available in the Fedora's package repository. It can also convert the number of code into a financial metric base according to some unknown theory. I am not expect how accurate it would be. It is just quite interesting.
If someone have the similar demands with mine, just have a try on this tool.
SLOCCount is just this kind of tool which is available in the Fedora's package repository. It can also convert the number of code into a financial metric base according to some unknown theory. I am not expect how accurate it would be. It is just quite interesting.
If someone have the similar demands with mine, just have a try on this tool.
Wednesday, 15 August 2012
Deploy Latex writing environment in Fedora 17
At the end of my PhD, a thesis writing with Latex is inevitable. However the Latex is not my primary writing tool during the whole process of my PhD. The Microsoft word seems more easy and intuitive when some small pieces of work are required. In this case, I am going to construct the Latex writing environment before any composing are produced. The last time when I used the Latex for writing was three years ago for the first year long report. It was all accomplished in an apple Mac environment with simple installation process and intuitive user interface. As for this time, I will complete all works in Linux environment. Here I will review how to produce a work using Latex in Linux firstly.
Simple work process:
In order to use the Latex in Fedora, some packages should be installed at the first place. Here is a collection of install packages which are available in Fedora 17 's yum package installation tool:
Using a light-weight text editor to manipulate a latex document is really painful, at least for me. So I found another package available in yum repository:
Simple work process:
- Composing the latex document.
- Compile the latex document: latex <filename.tex>
- Review the dvi file: xdvi <filename.dvi>
- Produce the pdf file: pdflatex <filename.tex>
In order to use the Latex in Fedora, some packages should be installed at the first place. Here is a collection of install packages which are available in Fedora 17 's yum package installation tool:
- texlive: for latex environment.
- texlive-latex: for latex command for front end program.
- xdvik: for dvi viewer.
Using a light-weight text editor to manipulate a latex document is really painful, at least for me. So I found another package available in yum repository:
- texmaker
Monday, 13 August 2012
Dual Monitors on Fedora 17 with Nvidia
I just too excited about my new Nvidia Graphic Card, to take the consideration of Linux driver installation into account. So, here is my updated specification in my little white box:
The problem was shown up when I switched from the i5 integrated Graphic Unit HD4000 to the new external EVGA gtx670 ftw Graphic Card, without changing on my original Operating Systems: Fedora 17 and Windows 7 dual system setting.
On the Windows 7, the EVGA graphic card works fine after installing the card driver software. On the Fedora 17, however, only one display (with smaller resolution) is recognised and the other one (with bigger resolution) is mirrored from that one with the same display resolution. (Sometimes another thing happens. The bigger resolution display is recognised and the smaller resolution display cannot display in that high resolution and then it is totally black.) There is no way to modify display settings like the control panel in Windows to add another display by using the provided display setting GUI tools. In this case, I decide to install the official Nvidia Linux driver to make the new graphic card work in Fedora 17.
Unfortunately, I was failed to install official Nvidia Linux driver. At first, the driver require me to disable the Nouveau driver before the installation of Nvidia driver. After that some other messages are shown on the screen. I cannot remember them. Actually, I didn't know what is really wrong with my installation procedure. But the problem persists after my installation. I assume my installation is unsuccessful at the first place. But I have found some others have already accomplished some work for installing the Nvidia driver in Linux environment.
According to an article on the Internet, the RPM fusion provide the kernel module of the Nvidia driver. This is quite similar with the wireless driver for ASUS's P8Z77-V-Deluxe motherboard which is composed in another my blog. The command used for installing is:
yum install akmod-nvidia xorg-x11-drv-nvidia-libs
By using the akmod package make me not concerned with the kernel update problem. The last step is to disable the Nouveau driver by:
- CPU: i5-3570K
- GPU: EVGA gtx670 ftw
- MEM: 8G 1600Mhz
- Hard_DISK: WD-Black 1T, WD-Blue 500G x 2
- PSU: Corsair AX850
- Motherboard: ASUS P8Z77-V-Deluxe
- Displays: 24" & 19" Samsung
The problem was shown up when I switched from the i5 integrated Graphic Unit HD4000 to the new external EVGA gtx670 ftw Graphic Card, without changing on my original Operating Systems: Fedora 17 and Windows 7 dual system setting.
On the Windows 7, the EVGA graphic card works fine after installing the card driver software. On the Fedora 17, however, only one display (with smaller resolution) is recognised and the other one (with bigger resolution) is mirrored from that one with the same display resolution. (Sometimes another thing happens. The bigger resolution display is recognised and the smaller resolution display cannot display in that high resolution and then it is totally black.) There is no way to modify display settings like the control panel in Windows to add another display by using the provided display setting GUI tools. In this case, I decide to install the official Nvidia Linux driver to make the new graphic card work in Fedora 17.
Unfortunately, I was failed to install official Nvidia Linux driver. At first, the driver require me to disable the Nouveau driver before the installation of Nvidia driver. After that some other messages are shown on the screen. I cannot remember them. Actually, I didn't know what is really wrong with my installation procedure. But the problem persists after my installation. I assume my installation is unsuccessful at the first place. But I have found some others have already accomplished some work for installing the Nvidia driver in Linux environment.
According to an article on the Internet, the RPM fusion provide the kernel module of the Nvidia driver. This is quite similar with the wireless driver for ASUS's P8Z77-V-Deluxe motherboard which is composed in another my blog. The command used for installing is:
yum install akmod-nvidia xorg-x11-drv-nvidia-libs
By using the akmod package make me not concerned with the kernel update problem. The last step is to disable the Nouveau driver by:
## Backup old initramfs nouveau image ## mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img ## Create new initramfs image ## dracut /boot/initramfs-$(uname -r).img $(uname -r)
reboot
Tuesday, 26 June 2012
Install MySQL and Development environment in Fedora 17
The installation of MySQL in Fedora is easy and trivial task because the MySQL server package is available in official yum repository. It can be installed both by yum and GUI installer.
The most important task is to configure the MySQL into a usable basic status. Because the Fedora 16/17 introduced another system service manipulating program, "systemctl", which is recommended by Fedora 16/17 in their deployment documentations, the configuration procedure is a little different from the previous Fedora systems that use "service" and "chkconfig" commands. These old programs, however, are still accessible in Fedora 16/17. Here is an example of "systemctl" usage:
Notice that the service name is followed by a word "service".
Enabling a service to start automatically at boot time:
Disabling a service to start at boot time:
Checking the service status:
Running, Stoping and Restarting a service:
After the MySQL service is started and is added to the start queue at boot time, several privilege settings should be done. There are many methods to accomplish this task. I'd like to use the provided program: "mysql_secure_installation". When this step is completed, the password for root is changed, and the anonymous account and test database should be properly set as desired.
In order to access the MySQL from remote machines, do not forget to open the port 3306 for the MySQL server.
More configurations and database set up can be done by using the GUI workbench of MySQL.
The most important task is to configure the MySQL into a usable basic status. Because the Fedora 16/17 introduced another system service manipulating program, "systemctl", which is recommended by Fedora 16/17 in their deployment documentations, the configuration procedure is a little different from the previous Fedora systems that use "service" and "chkconfig" commands. These old programs, however, are still accessible in Fedora 16/17. Here is an example of "systemctl" usage:
systemctl status mysqld.service
Notice that the service name is followed by a word "service".
Enabling a service to start automatically at boot time:
systemctl enable mysqld.service
Disabling a service to start at boot time:
systemctl disable mysqld.service
Checking the service status:
systemctl status mysqld.service
Running, Stoping and Restarting a service:
systemctl [start | stop | restart] mysqld.service
After the MySQL service is started and is added to the start queue at boot time, several privilege settings should be done. There are many methods to accomplish this task. I'd like to use the provided program: "mysql_secure_installation". When this step is completed, the password for root is changed, and the anonymous account and test database should be properly set as desired.
In order to access the MySQL from remote machines, do not forget to open the port 3306 for the MySQL server.
More configurations and database set up can be done by using the GUI workbench of MySQL.
Subscribe to:
Posts (Atom)