[1] http://bytes.com/topic/c/answers/624119-how-do-you-declare-use-static-constant-array-inside-class
[2] http://www.cplusplus.com/forum/beginner/2052/
HOW DO WE DECLARE AND INITIALIZE CONSTANT CHAR ARRAY? [1]
-----------------------------------------------------------
class Test
{
public:
static const int arr[]= {1,2,3}; // LINE 11
}
You can declare it here, but you can't initialize it here.
Initialize it in a separate definition.
Otherwise, you will get compiling error
"a brace-enclosed initializer is not allowed here before '{' token"
Header file:
class Test
{
public:
static const int arr[];
};
Implementation file in *.cpp:
const int Test::arr[3] = {1,2,3};
iostream linker error is solved by using g++ instead of gcc in makefile.
-----------------------------------------------------------------
Mistake to avoid when using 'inline'
-------------------------------------------------------------
1.Don't put inline in front of class constructor/destructor
2.Don't put inline in front of functions within 'namespace'.
linker error when using static variables in class [2]
--------------------------------------------------------
Tuesday, September 28, 2010
Wednesday, September 15, 2010
Vi / Vim Notes
[1] vim.org tagbar plugin
[2] vimawesome.com vim plugin\
[3] linux.com vim-101-a-beginners-guide-to-vim
[4] derickbailey/2010/04/23/using-vim-as-your-c-code-editor-from-visual-studio/
[5] cscope.sourceforge.net/cscope_vim_tutorial.html
qyang@lubuntu-laptop:~$ tree ~/.vim
/home/qyang/.vim
├── autoload
│ ├── acp.vim
│ └── tagbar.vim
├── doc
│ ├── acp.jax
│ ├── acp.txt
│ ├── tagbar.txt
│ ├── tags
│ └── tags-ja
├── plugin
│ ├── cscope_maps.vim
│ └── tagbar.vim
├── plugins
│ ├── acp.vim
│ ├── cctree.vim
│ ├── ming.vim
│ └── qt.vim
├── README.md
└── syntax
├── python.vim
└── tagbar.vim
ming.vim
set showcmd
set ruler
set nocompatible
set ignorecase smartcase incsearch hlsearch
set nowrap
set smartindent
set backspace=indent,eol,start
function Setcohda(...)
set tabstop=2 shiftwidth=2
set expandtab
endfunction
function Setlinux(...)
set tabstop=8 shiftwidth=8
set noexpandtab
endfunction
command Cohda call Setcohda()
command Linux call Setlinux()
autocmd FileType cpp Cohda
autocmd FileType make set noexpandtab tabstop=8
autocmd FileType python set tabstop=4 shiftwidth=4 noexpandtab
noremap :!make
inoremap :!make
qt.vim
------------------------------------
Generate cscope.out on root directory of source code project, then start vim from that root directory. All symbols index in cscope.out can be used by vim now.
Try below to jump straight to the file including 'main' symbol
Insert following code into makefile to generate cscope.out via make.
DISPLAY TAB
---------------------
Not quite work correctly to show all tabs
:SeeTab vim.wikia.com
OPEN MULTIPLE FILES FROM CMD LINE
-------------------------
TURN ON LINE NUMBER
------------------------
:set number
REPLACE A STRING
-------------------
:1,$s/word1/word2/gc IN A WHOLE FILE
:n1,n2s/word1/word2/gc IN BETWEEN LINE 'n1' and 'n2', special character use '\' prefix. (e.g.,:1,$s/word\[/word1\[/gc, replace 'word[' with 'word1[' )
COMMAND MODE
---------------------
'g0' -- go zero, go to head of line;
'g$' -- go to end of line;
'G' -- go to end of this file;
'H' -- go to top of screen;
'M' -- go to middle of screen;
'L' -- go to bottom of screen;
'nG' -- go to line number 'n'
'/word' -- search a string 'word' forward;
'?word' -- search a string 'word' backward;
'nyy' -- yank/copy n lines after cursor;
'p' -- paste yanked contens one line below cursor;
'dd' -- delete current line;
'nd' -- delete n lines after cursor;
DELETE/COPY(YANK) A BLOCK OF TEXT
----------------------------
The ‘mark command can be very useful when deleting a long series of lines.To
delete a long series of lines, follow these steps:
1. Move the cursor to the beginning of the text you want to delete.
2. Mark it using the command ma. (This marks it with mark a.)
3. Go to the end of the text to be removed. Delete to mark a using the command
d’a.
Note:There is nothing special about using the a mark. Any mark from a to z
may be used.
BACK TO PREVIOUSLY VISITED LOCATION previous view
-----------------------------
Ctrl + O
Ctrl + I (tab)
Jumping_to_previously_visited_locations
JUMP TO SYMBOL DEFINITION when ctags/cscope enabled
------------------------------
Ctrl + ]
Ctrl + T
A 05 Vi Exercise
===============================
[1] http://stackoverflow.com/questions/1737163/traversing-text-in-insert-mode
Insert mode and navigation mode switch
----------------------------------------
ESC or Ctrl+[
Navigation Fast
--------------------
15 + h go backward 15 characters
5 + j go forward 5 lines
Ctrl+o + 2 + b navigate two words back without leaving insert mode
Ctrl+o will give you chance to run one vi command at navigation
mode, then return to insert mode automatically.
'+. back to previous editing place after navigation
Type 20 '-' delete backword 9 '-'
----------------------------------------
20 + i + - + ESC
9 + X
'20' set number of execute times
'i' into insert mode
'-' letter or words you want to repeat
'ESC' back to navigation mode will display all insert letters.
'9' set number of exectue times
'X' delete backward, 'x' delete forward
Paste from clip board
-----------------------------------
"+p
" use register
+ clipboard register index
p paste shortcut key
Corret Typo
----------------------
accifently
FfrdA will correct the word from accifently to accidently
'F' find backward 'f' find forward
'f' find letter 'f'
'r' replace current cursor
'd' type correct letter 'd'
'A' back to original edit place
Rewrite word
--------------------
you accidentlly typed
you intentially typed
you intertially typed
ESC + 2 + b + c + w intentially + ESC + A
Write words in multiple lines
--------------------
[2] http://vim.wikia.com/wiki/Inserting_text_in_multiple_lines
hello
hello
hello
hel:added:loappend
hel:added:loappend
hel:added:loappend
hllo hello append
hllo hello append
hllo hello append
Ctrl+v + navigate coursor to 'l' + j + j + j + I + :added: + ESC
Ctrl+v + navigate coursor to 'o' + l + A + Ctrl+R + "
Ctrl+v + select block you want to delete + d
'Ctrl+v' visual block mode.
'I' insert before current cursor in visual block mode.
'A' append after current cursor in visual block mode.
'Ctrl + R + "' past yank register in insert mode
'Ctrl + R + +' past clipboard insert mode.
[2] vimawesome.com vim plugin\
[3] linux.com vim-101-a-beginners-guide-to-vim
[4] derickbailey/2010/04/23/using-vim-as-your-c-code-editor-from-visual-studio/
[5] cscope.sourceforge.net/cscope_vim_tutorial.html
qyang@lubuntu-laptop:~$ tree ~/.vim
/home/qyang/.vim
├── autoload
│ ├── acp.vim
│ └── tagbar.vim
├── doc
│ ├── acp.jax
│ ├── acp.txt
│ ├── tagbar.txt
│ ├── tags
│ └── tags-ja
├── plugin
│ ├── cscope_maps.vim
│ └── tagbar.vim
├── plugins
│ ├── acp.vim
│ ├── cctree.vim
│ ├── ming.vim
│ └── qt.vim
├── README.md
└── syntax
├── python.vim
└── tagbar.vim
ming.vim
qt.vim
------------------------------------
: colorscheme morning : syntax on : autocmd FileType * set formatoptions=tcql nocindent comments& : autocmd InsertEnter * colorscheme blue : autocmd InsertLeave * colorscheme morning : set autowrite : ab #d #define : ab #i #include : ab #b /******************************************************** : ab #e ^H^H********************************************************/ : ab #l /*------------------------------------------------------*/ : set sw=4 : set notextmode : set notextauto : set hlsearch : set incsearch : set textwidth=150 : au BufWinEnter * let w:m1=matchadd('Search','\%<151v .="">77v', -1) : au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>150v.\+', -1) : autocmd FileType c,cpp set formatoptions=croql cindent comments=sr: /*,mb: *.ex: */,: // : set nowrap : match ErrorMsg '\%>80v.\+' : set expandtab : set shiftwidth=2 : set softtabstop=2 : map: s/^/\/\// 151v>: map : s/^\/\/// : set smartcase : set ic
: nmap :TagbarToggle func! DeleteTrailingWS() exe "normal mz" %s/\s\+$//ge exe "normal `z" endfunc autocmd BufWrite *.py : call DeleteTrailingWS()
Generate cscope.out on root directory of source code project, then start vim from that root directory. All symbols index in cscope.out can be used by vim now.
Try below to jump straight to the file including 'main' symbol
$vi -t main
Insert following code into makefile to generate cscope.out via make.
$make cscope -f MakefileName
# Make software # # Generate csope files cscope: cscope.out cscope.out: cscope.files @cscope -R -b -i $< cscope.files: @find am335x -name "*.[ch]" -not -path "*/bootloader/*" > $@ && \ find libs -name "*.[ch]" -not -path "*/kissfft/*" >> $@ && \ find am335x -name "*.cpp" -o -name "*.h" -not -path "*/bootloader/*" >> find rtos -name "*.c" -o -name "*.h" -o -name "*.cpp" >> $@ clean: @rm cscope.*
DISPLAY TAB
---------------------
Not quite work correctly to show all tabs
:SeeTab vim.wikia.com
OPEN MULTIPLE FILES FROM CMD LINE
-------------------------
qyang@lubuntu-laptop:~/Git_Local_Sandbox/PcapPlot$ vi -g -p *.sh *.py 12 files to edit
TURN ON LINE NUMBER
------------------------
:set number
REPLACE A STRING
-------------------
:1,$s/word1/word2/gc IN A WHOLE FILE
:n1,n2s/word1/word2/gc IN BETWEEN LINE 'n1' and 'n2', special character use '\' prefix. (e.g.,:1,$s/word\[/word1\[/gc, replace 'word[' with 'word1[' )
COMMAND MODE
---------------------
'g0' -- go zero, go to head of line;
'g$' -- go to end of line;
'G' -- go to end of this file;
'H' -- go to top of screen;
'M' -- go to middle of screen;
'L' -- go to bottom of screen;
'nG' -- go to line number 'n'
'/word' -- search a string 'word' forward;
'?word' -- search a string 'word' backward;
'nyy' -- yank/copy n lines after cursor;
'p' -- paste yanked contens one line below cursor;
'dd' -- delete current line;
'nd' -- delete n lines after cursor;
DELETE/COPY(YANK) A BLOCK OF TEXT
----------------------------
The ‘mark command can be very useful when deleting a long series of lines.To
delete a long series of lines, follow these steps:
1. Move the cursor to the beginning of the text you want to delete.
2. Mark it using the command ma. (This marks it with mark a.)
3. Go to the end of the text to be removed. Delete to mark a using the command
d’a.
Note:There is nothing special about using the a mark. Any mark from a to z
may be used.
BACK TO PREVIOUSLY VISITED LOCATION previous view
-----------------------------
Ctrl + O
Ctrl + I (tab)
Jumping_to_previously_visited_locations
JUMP TO SYMBOL DEFINITION when ctags/cscope enabled
------------------------------
Ctrl + ]
Ctrl + T
A 05 Vi Exercise
===============================
[1] http://stackoverflow.com/questions/1737163/traversing-text-in-insert-mode
Insert mode and navigation mode switch
----------------------------------------
ESC or Ctrl+[
Navigation Fast
--------------------
15 + h go backward 15 characters
5 + j go forward 5 lines
Ctrl+o + 2 + b navigate two words back without leaving insert mode
Ctrl+o will give you chance to run one vi command at navigation
mode, then return to insert mode automatically.
'+. back to previous editing place after navigation
Type 20 '-' delete backword 9 '-'
----------------------------------------
20 + i + - + ESC
9 + X
'20' set number of execute times
'i' into insert mode
'-' letter or words you want to repeat
'ESC' back to navigation mode will display all insert letters.
'9' set number of exectue times
'X' delete backward, 'x' delete forward
Paste from clip board
-----------------------------------
"+p
" use register
+ clipboard register index
p paste shortcut key
Corret Typo
----------------------
accifently
FfrdA will correct the word from accifently to accidently
'F' find backward 'f' find forward
'f' find letter 'f'
'r' replace current cursor
'd' type correct letter 'd'
'A' back to original edit place
Rewrite word
--------------------
you accidentlly typed
you intentially typed
you intertially typed
ESC + 2 + b + c + w intentially + ESC + A
Write words in multiple lines
--------------------
[2] http://vim.wikia.com/wiki/Inserting_text_in_multiple_lines
hello
hello
hello
hel:added:loappend
hel:added:loappend
hel:added:loappend
hllo hello append
hllo hello append
hllo hello append
Ctrl+v + navigate coursor to 'l' + j + j + j + I + :added: + ESC
Ctrl+v + navigate coursor to 'o' + l + A + Ctrl+R + "
Ctrl+v + select block you want to delete + d
'Ctrl+v' visual block mode.
'I' insert before current cursor in visual block mode.
'A' append after current cursor in visual block mode.
'Ctrl + R + "' past yank register in insert mode
'Ctrl + R + +' past clipboard insert mode.
Gcc Command line based quick compiling
task2.cpp
#include
using namespace std;
int main()
{
char line[100];
cin >> line;
cout << "input data stream is:\n"<
}
[q.yang@localhost Sandbox]$ g++ task2.cpp -o task2
[q.yang@localhost Sandbox]$ ll
total 28
-rwxr-xr-x 1 q.yang developer 6392 2010-09-16 12:44 task2
-rw-r--r-- 1 q.yang developer 168 2010-09-16 12:31 task2.cpp
-rw-r--r-- 1 q.yang developer 1976 2010-09-16 12:34 task2.o
[q.yang@localhost Sandbox]$ ./task2
hello
input data stream is:
hello
Added new user account and set up VNC.
ADD USER THAT BELONG TO A GROUP
--------------------------------------
[root@localhost q.yang]# useradd -g developer guest
ADD USER
-------------------
#useradd john
MODIFY USER ACCOUNT
------------------
#usermod
SET PASSWORD for NEW USER
-----------------------------
#passwd john
[q.yang@localhost ~]$ ll /home/
total 20
drwx------ 4 guest developer 4096 2010-09-16 11:14 guest
drwx------ 2 root root 4096 2010-07-20 07:29 lost+found
drwx------ 38 q.yang q.yang 4096 2010-09-16 11:14 q.yang
CHANGE GROUP OWNERSHIP FOR ALL FILES IN PATH ./
--------------------------------------------------
[q.yang@localhost ~]$ chgrp -Rv developer ./
--------------------------------------
[root@localhost q.yang]# useradd -g developer guest
ADD USER
-------------------
#useradd john
MODIFY USER ACCOUNT
------------------
#usermod
SET PASSWORD for NEW USER
-----------------------------
#passwd john
[q.yang@localhost ~]$ ll /home/
total 20
drwx------ 4 guest developer 4096 2010-09-16 11:14 guest
drwx------ 2 root root 4096 2010-07-20 07:29 lost+found
drwx------ 38 q.yang q.yang 4096 2010-09-16 11:14 q.yang
CHANGE GROUP OWNERSHIP FOR ALL FILES IN PATH ./
--------------------------------------------------
[q.yang@localhost ~]$ chgrp -Rv developer ./
Subscribe to:
Posts (Atom)