Friday, August 31, 2012

CString vs std::string




cstring makes string.h accessable in namnespace std. cstring is located 
in /usr/include/c++ in my case. If you can't find it, just look for it 
by typing

locate cstring

It should be in a subdir of /usr/include


The file contains a comment, which might be useful:

/** @file cstring
* This is a Standard C++ Library file. You should @c #include this file
* in your programs, rather than any of the "*.h" implementation files.
*
* This is the C++ version of the Standard C Library header @c string.h,
* and its contents are (mostly) the same as that header, but are all
* contained in the namespace @c std.
*/

The Microsoft CString was written before the STL (and thus before std::string), but they are both designed to do basically the same thing.

The STL string has better out-of-the-box interoperability with STL algorithms.
The MS string has some really nice member functions.

Choose the one that suits your needs best.


Efficient in what sense?

the std::string will allow you to program more efficiently in terms of how you manage your time. Of course you can use it incorrectly and write really bad programs regardless of whether you define strings as char[] arrays or std::string objects. I just don't think that it is a fair question to be honest with you. Try defining some requirements. Write the program once with only c strings and once with std::string. Profile both programs and also keep track of how much time you spent writing each program. Look at the generated assembly code for each. There are a lot of factors to consider. Then report to us which is more efficient.



If you're using MFC, CString is a far better choice over std::string.
IMHO, CString is the only MFC class that is better then the STL version.

The std::string that comes with VC++ 6.0/7.x is very inefficient compare to CString.

std::string peforms very badly compare to CString.

Also IMHO, CString has a better string interface then std::string does.

CString is also easier to code when you want to be able to compile a project to either UNICODE or ANSI.

CString has an operator LPCTSTR(), so you don't have to explicitly cast.
With std::string, you have to use the c_str() member function to pass the pointer.
This point can also be consider a CON, but IMHO, the benifit far aways the down side.

CString has a GetBuffer() function which allows you to modify the buffer directly.
According to the C++ standard there's no portable way to modify the std::string buffer directly.

CString has a CompareNoCase function so you can make case insensitive comparisons.

CString works easier with many MFC and Windows API functions.

The major CON with CString is that is not portable. However, there are some CString versions on the net that are portable.


For more:
> > C headers exist in C++ in the form and the main difference is> that in the "no .h" form, all symbols (except macros) are declared in the> 'std' namespace. The .h form supposedly brings both std:: and regular> symbols. However, as admitted many times by library implementors, it is> rather difficult to follow those requirements. So, often the resulting> implementation is kind of in reverse: has all symbols in the> global namespace and has it in both global and 'std'. That's> my understanding of it, anyway.> 
Your understanding is correct. The safe rule is that if you want the 
names to be in the global namespace, use ; if you want them to 
be in std::, use .

Thursday, August 23, 2012

Bash script: Stay Out Of Trouble






String Comparison Result 
string1 = string2                                            True if the strings are equal. 
string1 != string2                                          True if the strings are not equal. 
-n string                                                            True if the string is not null. 
-z string                                                            True if the string is null (an empty string).


Arithmetic Comparison Result 
expression1 -eq expression2 True if the expressions are equal. 
expression1 -ne expression2 True if the expressions are not equal. 
expression1 -gt expression2 True if expression1is greater than expression2. 
expression1 -ge expression2 True if expression1is greater than or equal to 
expression2. 
expression1 -lt expression2 True if expression1is less than expression2. 
expression1 -le expression2 True if expression1is less than or equal to 
expression2. 
! expression True if the expression is false, and vice versa.



File Conditional Result 
-d file True if the file is a directory. 
-e file True if the file exists. Note that, historically, the -e option has not 
been portable, so -f is usually used. 
-f file True if the file is a regular file. 
-g file True if set-group-id is set on file. 
-r file True if the file is readable. 
-s file True if the file has nonzero size. 
-u file True if set-user-id is set on file. 
-w file True if the file is writable. 
-x file True if the file is executable. 






Debugging Scripts 


Command Line Option setOption Description 
sh -n

Wednesday, June 6, 2012

errno, perror, strerr




Diagrams
http://bramp.github.io/js-sequence-diagrams/


IDE one:
http://ideone.com
Ideone is an online compiler and debugging tool which allows you to compile source code and execute it online in more than 60 programming languages.



errno.h - C Error Codes in Linux


cat /usr/include/asm-generic/errno-base.h
#ifndef _ASM_GENERIC_ERRNO_BASE_H
#define _ASM_GENERIC_ERRNO_BASE_H

#define EPERM            1      /* Operation not permitted */
#define ENOENT           2      /* No such file or directory */
#define ESRCH            3      /* No such process */
#define EINTR            4      /* Interrupted system call */
#define EIO              5      /* I/O error */
#define ENXIO            6      /* No such device or address */
#define E2BIG            7      /* Argument list too long */
#define ENOEXEC          8      /* Exec format error */
#define EBADF            9      /* Bad file number */
#define ECHILD          10      /* No child processes */
#define EAGAIN          11      /* Try again */
#define ENOMEM          12      /* Out of memory */
#define EACCES          13      /* Permission denied */
#define EFAULT          14      /* Bad address */
#define ENOTBLK         15      /* Block device required */
#define EBUSY           16      /* Device or resource busy */
#define EEXIST          17      /* File exists */
#define EXDEV           18      /* Cross-device link */
#define ENODEV          19      /* No such device */
#define ENOTDIR         20      /* Not a directory */
#define EISDIR          21      /* Is a directory */
#define EINVAL          22      /* Invalid argument */
#define ENFILE          23      /* File table overflow */
#define EMFILE          24      /* Too many open files */
#define ENOTTY          25      /* Not a typewriter */
#define ETXTBSY         26      /* Text file busy */
#define EFBIG           27      /* File too large */
#define ENOSPC          28      /* No space left on device */
#define ESPIPE          29      /* Illegal seek */
#define EROFS           30      /* Read-only file system */
#define EMLINK          31      /* Too many links */
#define EPIPE           32      /* Broken pipe */
#define EDOM            33      /* Math argument out of domain of func */
#define ERANGE          34      /* Math result not representable */

#endif


cat /usr/include/asm-generic/errno.h
#ifndef _ASM_GENERIC_ERRNO_H
#define _ASM_GENERIC_ERRNO_H

#include 

#define EDEADLK         35      /* Resource deadlock would occur */
#define ENAMETOOLONG    36      /* File name too long */
#define ENOLCK          37      /* No record locks available */
#define ENOSYS          38      /* Function not implemented */
#define ENOTEMPTY       39      /* Directory not empty */
#define ELOOP           40      /* Too many symbolic links encountered */
#define EWOULDBLOCK     EAGAIN  /* Operation would block */
#define ENOMSG          42      /* No message of desired type */
#define EIDRM           43      /* Identifier removed */
#define ECHRNG          44      /* Channel number out of range */
#define EL2NSYNC        45      /* Level 2 not synchronized */
#define EL3HLT          46      /* Level 3 halted */
#define EL3RST          47      /* Level 3 reset */
#define ELNRNG          48      /* Link number out of range */
#define EUNATCH         49      /* Protocol driver not attached */
#define ENOCSI          50      /* No CSI structure available */
#define EL2HLT          51      /* Level 2 halted */
#define EBADE           52      /* Invalid exchange */
#define EBADR           53      /* Invalid request descriptor */
#define EXFULL          54      /* Exchange full */
#define ENOANO          55      /* No anode */
#define EBADRQC         56      /* Invalid request code */
#define EBADSLT         57      /* Invalid slot */

#define EDEADLOCK       EDEADLK

#define EBFONT          59      /* Bad font file format */
#define ENOSTR          60      /* Device not a stream */
#define ENODATA         61      /* No data available */
#define ETIME           62      /* Timer expired */
#define ENOSR           63      /* Out of streams resources */
#define ENONET          64      /* Machine is not on the network */
#define ENOPKG          65      /* Package not installed */
#define EREMOTE         66      /* Object is remote */
#define ENOLINK         67      /* Link has been severed */
#define EADV            68      /* Advertise error */
#define ESRMNT          69      /* Srmount error */
#define ECOMM           70      /* Communication error on send */
#define EPROTO          71      /* Protocol error */
#define EMULTIHOP       72      /* Multihop attempted */
#define EDOTDOT         73      /* RFS specific error */
#define EBADMSG         74      /* Not a data message */
#define EOVERFLOW       75      /* Value too large for defined data type */
#define ENOTUNIQ        76      /* Name not unique on network */
#define EBADFD          77      /* File descriptor in bad state */
#define EREMCHG         78      /* Remote address changed */
#define ELIBACC         79      /* Can not access a needed shared library */
#define ELIBBAD         80      /* Accessing a corrupted shared library */
#define ELIBSCN         81      /* .lib section in a.out corrupted */
#define ELIBMAX         82      /* Attempting to link in too many shared libraries */
#define ELIBEXEC        83      /* Cannot exec a shared library directly */
#define EILSEQ          84      /* Illegal byte sequence */
#define ERESTART        85      /* Interrupted system call should be restarted */
#define ESTRPIPE        86      /* Streams pipe error */
#define EUSERS          87      /* Too many users */
#define ENOTSOCK        88      /* Socket operation on non-socket */
#define EDESTADDRREQ    89      /* Destination address required */
#define EMSGSIZE        90      /* Message too long */
#define EPROTOTYPE      91      /* Protocol wrong type for socket */
#define ENOPROTOOPT     92      /* Protocol not available */
#define EPROTONOSUPPORT 93      /* Protocol not supported */
#define ESOCKTNOSUPPORT 94      /* Socket type not supported */
#define EOPNOTSUPP      95      /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT    96      /* Protocol family not supported */
#define EAFNOSUPPORT    97      /* Address family not supported by protocol */
#define EADDRINUSE      98      /* Address already in use */
#define EADDRNOTAVAIL   99      /* Cannot assign requested address */
#define ENETDOWN        100     /* Network is down */
#define ENETUNREACH     101     /* Network is unreachable */
#define ENETRESET       102     /* Network dropped connection because of reset */
#define ECONNABORTED    103     /* Software caused connection abort */
#define ECONNRESET      104     /* Connection reset by peer */
#define ENOBUFS         105     /* No buffer space available */
#define EISCONN         106     /* Transport endpoint is already connected */
#define ENOTCONN        107     /* Transport endpoint is not connected */
#define ESHUTDOWN       108     /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS    109     /* Too many references: cannot splice */
#define ETIMEDOUT       110     /* Connection timed out */
#define ECONNREFUSED    111     /* Connection refused */
#define EHOSTDOWN       112     /* Host is down */
#define EHOSTUNREACH    113     /* No route to host */
#define EALREADY        114     /* Operation already in progress */
#define EINPROGRESS     115     /* Operation now in progress */
#define ESTALE          116     /* Stale NFS file handle */
#define EUCLEAN         117     /* Structure needs cleaning */
#define ENOTNAM         118     /* Not a XENIX named type file */
#define ENAVAIL         119     /* No XENIX semaphores available */
#define EISNAM          120     /* Is a named type file */
#define EREMOTEIO       121     /* Remote I/O error */
#define EDQUOT          122     /* Quota exceeded */

#define ENOMEDIUM       123     /* No medium found */
#define EMEDIUMTYPE     124     /* Wrong medium type */
#define ECANCELED       125     /* Operation Canceled */
#define ENOKEY          126     /* Required key not available */
#define EKEYEXPIRED     127     /* Key has expired */
#define EKEYREVOKED     128     /* Key has been revoked */
#define EKEYREJECTED    129     /* Key was rejected by service */

/* for robust mutexes */
#define EOWNERDEAD      130     /* Owner died */
#define ENOTRECOVERABLE 131     /* State not recoverable */

#endif

Thursday, May 31, 2012

Job Ad






vav.info at yahoo com vn
Please let me know if you believe your experience and knowledge match the following:

       General
        Our products are based on the IS platform and mainly implemented using Erlang/OTP.
       Basic skills
        OTP/Erlang/IS competence
        Knowledge regarding the environment (Clearcase, Ericsson tools)
        Basic IMS
        SIP, H.248
        Agile/Scrum
        Written and spoken English
       Application specific skills:
        SBG specific knowledge (architecture, blocks)


       Included: 1 team (8 persons) for feature development
        Perform pre-studies, in selected cases support also the quick-study phase
        Design of the code for the assigned design objects.
        Design Documentation for the assigned design objects
        Coding (primarily Erlang)
        Unit Tests for the code.
        Function Test in a real SBG HW environment (where surrounding IMS nodes are simulated.), for feature development.
        Support to Ericsson concerning the developed parts (answering questions, etc.)
        Participation in task forces together with Ericsson if there are issues that require extra attention to handle.
        Later possibly also participation in early project phases (requirement analysis/definition, system level design, etc.).
        Working and tested software checked into the version handling system data store at Ericsson.
        Product/project documentation stored in the document archive at Ericsson.

Labels