More C Questions ....
Roger Oberholtzer
roger
Wed Sep 14 01:54:09 PDT 2005
On Tue, 2005-09-13 at 20:18, Ben Duncan wrote:
> Ok, in the following code snippet:
> ----------------------------------------------------------------------
> #ifdef SEMLOCK
> #if 1
> if ( ( sem_id = semget ( key, 1, 0 ) ) == -1 )
> if ( ( sem_id = semget ( key, 1, IPC_CREAT | 0660 ) ) == -1 )
> {
> shmdt ( ( char * ) db->shm );
> if ( created )
> shmctl ( db->shm_id, IPC_RMID, NULL );
> return -1;
> }
> #else
> if ( ( sem_id = sem_open ( key ) ) == -1 )
> if ( ( sem_id = sem_create ( key, 1 ) ) == -1 )
> {
> shmdt ( ( char * ) db->shm );
> if ( created )
> shmctl ( db->shm_id, IPC_RMID, NULL );
> return -1;
> }
> #endif
> #endif
> ------------------------------------------------------------------------
>
> I know that if there is a #define SEMLOCK somewhere in the code/header
> then the #ifdef SEMLOCK is going to get taken. BUT .. What is it with
> that #if 1 ? What is it doing, how does it get set ?
It is a programming trick. It does not get set. Change the '1' to a '0'
to select which method gets used when SEMLOCK is defined. Sometimes old
code is kept around for a bit this way as a sort of documentation. So,
you edit the file to change which bit of code gets used. It cannot be
set any other way. I am guilty of such behavior. But a comment telling
what is going on is never a bad thing to have here as well.
>
> Thanks ...
>
> I
>
>
>
+????????????????????????????+???????????????????????????????+
? Roger Oberholtzer ? E-mail: roger at opq.se ?
? OPQ Systems AB ? WWW: http://www.opq.se/ ?
? Kapellgr?nd 7 ? ?
? P. O. Box 4205 ? Phone: Int + 46 8 314223 ?
? 102 65 Stockholm ? Mobile: Int + 46 733 621657 ?
? Sweden ? Fax: Int + 46 8 314223 ?
+????????????????????????????+???????????????????????????????+
More information about the Linux-users
mailing list