Welcome, Guest. Please login or register.

Author Topic: Probably very basic C question...  (Read 2109 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
Probably very basic C question...
« on: May 25, 2004, 08:23:12 PM »
On the code at the bottom, what's the meaning of the ! operator in if(!LibBase)... ?
I tried to find it on some C book I have but ! seems to be the NOT operator. From what I understand the goal would be to evaluate the returned value of the function OpenLibrary and if not zero than the statements after If get done other wise the else part get's done (the basic If thing...).
But from the code below it's evaluating the negation of the  
returned Libase ?! Obviously this doesn't make sense so I'm missing something here.

P.S. No, I'm still not learning C, I'm just reading some parts of the Rom Kernel Manuals on my DevCD and some of the examples are in C only...

Code: [Select]

struct Library *LibBase;      /* Global: declare this above main() */

    main()
    {
    LibBase = OpenLibrary("library.name",version);

    if(!LibBase) { /* Library did not open, so exit        */ }
    else         { /* Library opened, so use its functions */ }
    }
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
Re: Probably very basic C question...
« Reply #1 on: May 25, 2004, 09:57:48 PM »
Pah, the assembler version is more straightforward :-)

Since all is needed is to evaluate if LibBase is Null then why not just use:
Code: [Select]

if(LibBase) statement1 /*do stuff if Library suceesfully opened e.g. LibBase not zero*/
else statement2 /* exit.. the thing didn't open*/


What is that bloody exclamtion point doing in there? Is it still acting as NOT ?
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2871
    • Show all replies
Re: Probably very basic C question...
« Reply #2 on: May 25, 2004, 10:14:19 PM »
Ahhh.. Ok I finally got it :-D
Cheers
\\"We made Amiga, they {bleep}ed it up\\"