Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
132 user(s) are online (131 user(s) are browsing Forums)

Members: 0
Guests: 132

more...

Support us!

Headlines

 
  Register To Post  

GCC and boolean ....
Quite a regular
Quite a regular


See User information
Hi All,

I encounter a small issue using boolean.
Here is my code :

1st part, the main C project :
#include <gl/glut.h>

int argc;
char** argv;

#include "setup.c"
#include "camera.c"
#include "core.c"

int mainint argcchar** argv ){
  
Constructor();
  
SetDisplayMode640480 );
  
Destructor();
  return 
0;
 }


And now, part of setup.c file :
/* Variables globales au fichier lib */
BOOL FullSCREEN;
int WindowID;

/* Procedure d'initialisation de la lib DISPLAY */
void Constructorvoid ){
  
FullSCREEN FALSE;
  
glutInit( &argcargv );                                       /* Initialize Glut */
/*  glutDisplayFunc( DisplayFunc ); */
/*  glutReshapeFunc( ReshapeFunc ); */
 
}

/* Procedure de la fermeture de la librairie DISPLAY */
void Destructorvoid ){
  
glutDestroyWindowWindowID );
 }

/* Cr?ation de la fen?tre d'affichage principale */
void SetDisplayModeint Widthint Height ){                    /* TO DO : MUST ADDED WITH TO InitDisplayMode */
  /* Open the screen using windowed mode */
  
glutInitDisplayModeGLUT_DOUBLE GLUT_RGBA );              /* Define display mode properties */
  
glutInitWindowSizeWidthHeight );
  
glutInitWindowPosition3232 );
  
WindowID == glutCreateWindow"AmiDARK Basic application" ); /* Create the asked window */
  
if (FullSCREEN TRUE){
    
glutGameModeString"640x480:32" );
    
glutEnterGameMode();
   }
 }


When I compile the main C file, it compiles correctly but, when I run it, it open a window and jump in fullscreen mode. It shouldn't jump in fullscreeen mode.
if I change in the SetDisplayMode() function, this line :
if (FullSCREEN TRUE){

with :
if (FullSCREEN FALSE){

then it run, open a window and quit correctly without using full screen mode...
Why does boolean act this way ? it should work as opposite than this . not ?

Kindest Regards,
Freddix

All we have to decide is what to do with the time that is given to us.
Go to top
Re: GCC and boolean ....
Just can't stay away
Just can't stay away


See User information
@freddix

Quote:

if (FullSCREEN = TRUE){


This condition will always be true since you're not doing a comparison but an assigment, i.e. your code is the same as:

Quote:

FullSCREEN = TRUE;
if (FullSCREEN){


What you want to do is either:

Quote:

if (FullSCREEN == TRUE){


or simply:

Quote:

if (FullSCREEN){

Go to top
Re: GCC and boolean ....
Quite a regular
Quite a regular


See User information
@salass00
Effectively,
I've re-read my C book and if comparizon need == instead of simple =.

Thank you.

All we have to decide is what to do with the time that is given to us.
Go to top
Re: GCC and boolean ....
Not too shy to talk
Not too shy to talk


See User information
@freddix

Quote:
if comparizon need == instead of simple =.


That's not exact. "==" is always a comparison, no matter where used and "=" is always an assignment, no matter where used. Unlike other programming languages, it is not related to "if" (or other places where conditions are used like "while" or "for").

Bye,
Thomas

Go to top
Re: GCC and boolean ....
Quite a regular
Quite a regular


See User information
@thomas
Ok

Now my dev work perfectly :)
Will add new functions :p

All we have to decide is what to do with the time that is given to us.
Go to top
Re: GCC and boolean ....
Amigans Defender
Amigans Defender


See User information
@freddix
Quote:

if (FullSCREEN = TRUE)

This is of course an assignment and I would have expected the compiler to warn you if you had -Wall on or similar.

I would also say this is bad coding style.
Here are my preferences:
if (FullSCREEN == TRUE) // ok
if (FullSCREEN) // better
if (IsFullScreen) // best

ExecSG Team Lead
Go to top
Re: GCC and boolean ....
Quite a regular
Quite a regular


See User information
@ssolie
Quote:

if (IsFullScreen) // best

Then you prefer IsFullScreen as bool to handle fullscreen mode state ?

All we have to decide is what to do with the time that is given to us.
Go to top
Re: GCC and boolean ....
Not too shy to talk
Not too shy to talk


See User information
@freddix

Quote:

freddix wrote:
@ssolie
Quote:

if (IsFullScreen) // best

Then you prefer IsFullScreen as bool to handle fullscreen mode state ?


it is always nice to follow some "naming conventions". and a very good and easy one is to name vaiables in a way that one can see (or guess) at first sight
- the type of the variable
- the meaning of the variable
- the scope of the variable

boolean -> prefeix like "is...", "has...", ... is very intuitive.
"FullScreen" tells the use
maybe missing is the scope. global or local. or a member of a class/instance, or static, or whatever. maybe not needed for smaller programs.

just my experience from my knowledge in our company.

byebye...

Go to top
Re: GCC and boolean ....
Quite a regular
Quite a regular


See User information
@MichaelMerkel
Ok
Thank you for these advices.

All we have to decide is what to do with the time that is given to us.
Go to top
Re: GCC and boolean ....
Quite a regular
Quite a regular


See User information
@freddix

Another way to prevent this kinf of unnoticed error, I would advise you to reverse your test use
if( TRUE == FullSCREEN)

This way in case you would forget a '=' sign the compiler would throw an error because you would then attempt to affect a value to a constant.

Back to a quiet home... At last
Go to top
Re: GCC and boolean ....
Quite a regular
Quite a regular


See User information
@abalaban:
Effectively, it's a good advice :)

All we have to decide is what to do with the time that is given to us.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project