Start New Discussion within our Software Development Community

hi ,
i have read that c99 introduced:
inline,_Bool,restrict,_Complex,_Imaginary

i have used _Bool here but do no how to use remaining all
please any one used the above can help me.

int main()
{
    _Bool b;
      b=true;// giving error  true undeclared ,cant i use that way 
                 // with out using enums.
       b =1;
       if ( b )
           printf (" ok\n");
        else
           printf("No\n");
return 0;
}

Thanks,
Danian.

include stdbool.h

The type is "bool"

e.g.

#include<stdbool.h>

bool b= true;

this works in my compiler(cc).

Comments
Thanks

inline: Similar to C++'s inline keyword. It gives you the option of telling the compiler that you want inline expansion rather than real function object code. Inline functions are a safer and easier to use alternative to function macros:

static inline swap ( int *a, int *b )
{
  int save = *a;
  *a = *b;
  *b = save;
}

I'd recommend avoiding this feature. Not only are the rules somewhat tricky, the compiler isn't required to honor a hint for inlining. Further, if the compiler does honor the hint, it could be counter-productive and actually hurt performance instead of help it by increasing the memory footprint and causing thrashing.

_Bool: C99's boolean type. Using _Bool directly is only recommended if you're maintaining legacy code that already defines macros for bool, true, or false. Otherwise, those macros are standardized in the <stdbool.h> header. Include that header and you can use bool just like you would in C++.

#include <stdio.h>
#include <stdbool.h>

int main ( void )
{
  bool b = true;

  if ( b )
    printf ( "Yes\n" );
  else
    printf ( "No\n" );

  return 0;
}

restrict: The restrict keyword is an optimization hint. It says that a pointer is not aliased in the current scope, which means the underlying object is not accessed by another pointer. This hint gives the compiler extra leeway in making assumptions about the pointer and can result in better object code. I'd recommend avoiding this feature too. A lot of people have trouble understanding restrict, and that confusion isn't worth the potential for optimization, in my opinion.

/* src and dst won't alias each other */
void b_copy ( void *restrict src, void *restrict dst, size_t nbytes );

_Complex and _Imaginary: These are keywords for working with complex numbers in C99 (obviously). You can safely ignore them until you need complex numbers (which also saves me the trouble of typing up a tutorial).

Comments
Nicely written info :)
thanks

inline: Similar to C++'s inline keyword. It gives you the option of telling the compiler that you want inline expansion rather than real function object code. Inline functions are a safer and easier to use alternative to function macros:

static inline swap ( int *a, int *b )
{
  int save = *a;
  *a = *b;
  *b = save;
}

I'd recommend avoiding this feature. Not only are the rules somewhat tricky, the compiler isn't required to honor a hint for inlining. Further, if the compiler does honor the hint, it could be counter-productive and actually hurt performance instead of help it by increasing the memory footprint and causing thrashing.

_Bool: C99's boolean type. Using _Bool directly is only recommended if you're maintaining legacy code that already defines macros for bool, true, or false. Otherwise, those macros are standardized in the <stdbool.h> header. Include that header and you can use bool just like you would in C++.

#include <stdio.h>
#include <stdbool.h>

int main ( void )
{
  bool b = true;

  if ( b )
    printf ( "Yes\n" );
  else
    printf ( "No\n" );

  return 0;
}

restrict: The restrict keyword is an optimization hint. It says that a pointer is not aliased in the current scope, which means the underlying object is not accessed by another pointer. This hint gives the compiler extra leeway in making assumptions about the pointer and can result in better object code. I'd recommend avoiding this feature too. A lot of people have trouble understanding restrict, and that confusion isn't worth the potential for optimization, in my opinion.

/* src and dst won't alias each other */
void b_copy ( void *restrict src, void *restrict dst, size_t nbytes );

_Complex and _Imaginary: These are keywords for working with complex numbers in C99 (obviously). You can safely ignore them until you need complex numbers (which also saves me the trouble of typing up a tutorial).

thanks for you replies

This question has already been answered. Start a new discussion instead.