Jump to content
• Advertisement

Public Group

# Converting Booleans

This topic is 3899 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hey, I'm using pointers for booleans right now and I don't get this Example 1
    bool* pBool;
bool bBool = false;
pBool = &bBool;
//pBool is still true


Example 2
    bool pBool;
bool bBool = false;
pBool = bBool;
//pBool is still true...


Is there any way of assigning a boolean to another boolean?

#### Share this post

##### Share on other sites
Advertisement
I dont see you dereferencing the pointer...

Try this:
    bool* pBool;    bool bBool = false;    pBool = &bBool;    std::cout << *pBool;

It should display 0(false)

Your second example should work. How are you determining if it is false or true? false is 0, true is any non-zero value.

#### Share this post

##### Share on other sites
If you're doing:
if (pBool) ....
then yes, it will always be true, unless you assign NULL to it.

Because you're not testing the boolean, but pointer. That would be the basic non-NULL pointer test.

To get value of pointed-to object, do:if (*pBool) ... 
 0 
 Share this post Link to post Share on other sites 
 
 
 Rad94    100 Rad94 Member 100 Posted March 18, 2008 0 is false? Oh in that case it worked. I assumed that since "return 0" was the same as returning true, 0 was true. Sorry about thatAnd thanks Antheus for helping me with the if(pBool) thing :) 0 Share this post Link to post Share on other sites 
 Sign in to follow this   Followers 0 
 Go To Topic Listing Forum 
 Advertisement 
 Advertisement Popular Tags 2D 3D Advice Algorithm Animation C# C++ Character Concept Design DX11 Education GameMaker Gameplay General Java Learning Marketing Mobile Music OpenGL PC Unity Unreal VR Popular Contributors Week Month Year All Time 1 Rutin 44 2 CyberFlash 24 3 Septopus 22 4 supermikhail 12 5 Gnollrunner 11 Show More Advertisement Popular Now 10 number of matching chars in 2 strings By ICanCStarted Sunday at 11:20 AM 28 collision sprite By phil67rpgStarted Friday at 10:13 PM 20 Pub/Sub for game Servers... Are you? By SeptopusStarted Thursday at 06:38 PM 9 C++ Dynamic memory using "new" and malloc() By rytStarted Thursday at 01:59 PM 20 Can I use assets from another game under these conditions? By JaretStarted November 13 Forum Statistics Total Topics 633409 Total Posts 3011702 Who's Online (See full list) There are no registered users currently online GameDev.net GameDev.net Articles GameDev.net Event Coverage GameDev.net Forums GameDev.net Blogs GameDev.net Gallery GameDev.net News GameDev.net Projects GDNet Chat All Activity Search In Everywhere This Forum This Topic More options... Find results that contain... All of my search term words Any of my search term words Find results in... Content titles and body Content titles only Home Groups For Beginners Forum Converting Booleans 
 
 
 × Existing user? Sign In Sign Up Browse Back Articles & Tutorials Back All Categories Audio Business Game Design Industry Programming Visual Arts Columns Back GameDev Unboxed Event Coverage Back All Events Game Developers Conference Power Up Digital Games Conference GameDev.Market Links News Podcasts Back All Podcasts Game Dev Loadout Archive Community Back Beginners Back Beginners Group Beginners Forum Beginners Resources Blogs Calendar Chat Forums Back All Forums Audio Business Game Design Programming Visual Arts Community GameDev Challenges Affiliates Topical Workshops Gallery Groups Back For Beginners GameDev Challenges All Groups Projects Back All Projects Games Game Assets Game Mods Developer Tools Store Forums Back All Forums For Beginners Audio Back Music and Sound FX Games Career Development Business Back Games Career Development Production and Management Games Business and Law Game Design Back Game Design and Theory Writing for Games Programming Back Artificial Intelligence Engines and Middleware General and Gameplay Programming Graphics and GPU Programming Math and Physics Networking and Multiplayer Visual Arts Back 2D and 3D Art Critique and Feedback Community Back GameDev Challenges GDNet Lounge GDNet Comments, Suggestions, and Ideas Coding Horrors Your Announcements Hobby Project Classifieds Indie Showcase Affiliates Back NeHe Productions AngelCode Topical Workshops Careers Back Contractors Hobby Projects Game Jobs Back Browse on GameDev.Jobs Post a Job Members Back Subscriptions Chat Guidelines Leaderboard Online Users Awards Search Back All Activity My Activity Streams Back Latest Topics Featured Blogs Search var ipsDebug = false; var CKEDITOR_BASEPATH = '//www.gamedev.net/applications/core/interface/ckeditor/ckeditor/'; var ipsSettings = { cookie_path: "/", cookie_prefix: "ips4_", cookie_ssl: true, upload_imgURL: "", message_imgURL: "", notification_imgURL: "", baseURL: "//www.gamedev.net/", jsURL: "//www.gamedev.net/applications/core/interface/js/js.php", csrfKey: "33915cfd1766cabe756d41fd5a0104fc", antiCache: "14de000c45", disableNotificationSounds: false, useCompiledFiles: true, links_external: true, memberID: 0, analyticsProvider: "ga", viewProfiles: true, mapProvider: 'google', mapApiKey: "AIzaSyAeT7tk3vnWWmbgVISkLpbhkQvekG19rHM", }; ips.setSetting( 'date_format', jQuery.parseJSON('"mm\/dd\/yy"') ); ips.setSetting( 'date_first_day', jQuery.parseJSON('0') ); ips.setSetting( 'remote_image_proxy', jQuery.parseJSON('1') ); ips.setSetting( 'ipb_url_filter_option', jQuery.parseJSON('"none"') ); ips.setSetting( 'url_filter_any_action', jQuery.parseJSON('"allow"') ); ips.setSetting( 'bypass_profanity', jQuery.parseJSON('0') ); ips.setSetting( 'emoji_style', jQuery.parseJSON('"native"') ); ips.setSetting( 'emoji_shortcodes', jQuery.parseJSON('"1"') ); ips.setSetting( 'emoji_ascii', jQuery.parseJSON('"1"') ); ips.setSetting( 'emoji_cache', jQuery.parseJSON('"1"') ); ips.setSetting( 'quickSearchDefault', jQuery.parseJSON('"all"') ); ips.setSetting( 'quickSearchMinimum', jQuery.parseJSON('3') ); ips.setSetting( 'quickSearchShowAdv', jQuery.parseJSON('true') ); ips.setSetting( 'quickSearchIn', jQuery.parseJSON('"title"') ); { "@context": "http://schema.org", "@type": "DiscussionForumPosting", "url": "https://www.gamedev.net/forums/topic/487180-converting-booleans/", "discussionUrl": "https://www.gamedev.net/forums/topic/487180-converting-booleans/", "name": "Converting Booleans", "headline": "Converting Booleans", "text": "Hey, I\u0027m using pointers for booleans right now and I don\u0027t get this\n\nExample 1\n\n\n bool* pBool;\n bool bBool = false;\n pBool = \u0026amp;bBool;\n //pBool is still true\n\n\n\nExample 2\n\n bool pBool;\n bool bBool = false;\n pBool = bBool;\n //pBool is still true...\n\n\n\nIs there any way of assigning a boolean to another boolean?", "dateCreated": "2008-03-17T20:02:45+0000", "datePublished": "2008-03-17T20:02:45+0000", "pageStart": 1, "pageEnd": 1, "image": "https://secure.gravatar.com/avatar/942cee56d76b2c8d20a26b5eb3f1e7d3?d=https://www.gamedev.net/uploads/monthly_2017_08/R.png.b93f2d93ac4e55a368f8076ff4816d03.png", "author": { "@type": "Person", "name": "Rad94", "image": "https://secure.gravatar.com/avatar/942cee56d76b2c8d20a26b5eb3f1e7d3?d=https://www.gamedev.net/uploads/monthly_2017_08/R.png.b93f2d93ac4e55a368f8076ff4816d03.png", "url": "https://www.gamedev.net/profile/125591-rad94/" }, "interactionStatistic": [ { "@type": "InteractionCounter", "interactionType": "http://schema.org/ViewAction", "userInteractionCount": 746 }, { "@type": "InteractionCounter", "interactionType": "http://schema.org/CommentAction", "userInteractionCount": 3 }, { "@type": "InteractionCounter", "interactionType": "http://schema.org/FollowAction", "userInteractionCount": 50 } ], "comment": [ { "@type": "Comment", "url": "https://www.gamedev.net/forums/topic/487180-converting-booleans/?do=findComment\u0026comment=487180", "author": { "@type": "Person", "name": "Rad94", "image": "https://secure.gravatar.com/avatar/942cee56d76b2c8d20a26b5eb3f1e7d3?d=https://www.gamedev.net/uploads/monthly_2017_08/R.png.b93f2d93ac4e55a368f8076ff4816d03.png", "url": "https://www.gamedev.net/profile/125591-rad94/" }, "dateCreated": "2008-03-17T20:02:45+0000", "text": "Hey, I\u0027m using pointers for booleans right now and I don\u0027t get this\n\nExample 1\n\n\n bool* pBool;\n bool bBool = false;\n pBool = \u0026amp;bBool;\n //pBool is still true\n\n\n\nExample 2\n\n bool pBool;\n bool bBool = false;\n pBool = bBool;\n //pBool is still true...\n\n\n\nIs there any way of assigning a boolean to another boolean?", "mainEntityOfPage": "https://www.gamedev.net/forums/topic/487180-converting-booleans/" }, { "@type": "Comment", "url": "https://www.gamedev.net/forums/topic/487180-converting-booleans/?do=findComment\u0026comment=4182645", "author": { "@type": "Person", "name": "Crypter", "image": "https://secure.gravatar.com/avatar/b63896dbe7236bfb0ed9d4083df85fa1?d=https://www.gamedev.net/uploads/monthly_2017_08/C.png.4401d001ebe56b433c698ba1aabda9c8.png", "url": "https://www.gamedev.net/profile/66590-crypter/" }, "dateCreated": "2008-03-17T20:10:11+0000", "text": "I dont see you dereferencing the pointer...Try this:\n bool* pBool; bool bBool = false; pBool = \u0026amp;bBool; std::cout \u0026lt;\u0026lt; *pBool;\nIt should display 0(false)Your second example should work. How are you determining if it is false or true? false is 0, true is any non-zero value.", "mainEntityOfPage": "https://www.gamedev.net/forums/topic/487180-converting-booleans/" }, { "@type": "Comment", "url": "https://www.gamedev.net/forums/topic/487180-converting-booleans/?do=findComment\u0026comment=4182661", "author": { "@type": "Person", "name": "Antheus", "image": "https://secure.gravatar.com/avatar/cf0a6ebb73e97e86ae20ae3972d87fd9?d=https://www.gamedev.net/uploads/monthly_2017_08/A.png.e39185feff92ce1b36db2bf96e3bae9e.png", "url": "https://www.gamedev.net/profile/98463-antheus/" }, "dateCreated": "2008-03-17T20:51:49+0000", "text": "If you\u0027re doing:\nif (pBool) .... then yes, it will always be true, unless you assign NULL to it.Because you\u0027re not testing the boolean, but pointer. That would be the basic non-NULL pointer test.To get value of pointed-to object, do:if (*pBool) ...\n", "mainEntityOfPage": "https://www.gamedev.net/forums/topic/487180-converting-booleans/" }, { "@type": "Comment", "url": "https://www.gamedev.net/forums/topic/487180-converting-booleans/?do=findComment\u0026comment=4183170", "author": { "@type": "Person", "name": "Rad94", "image": "https://secure.gravatar.com/avatar/942cee56d76b2c8d20a26b5eb3f1e7d3?d=https://www.gamedev.net/uploads/monthly_2017_08/R.png.b93f2d93ac4e55a368f8076ff4816d03.png", "url": "https://www.gamedev.net/profile/125591-rad94/" }, "dateCreated": "2008-03-18T17:35:42+0000", "text": "0 is false? Oh in that case it worked. I assumed that since \"return 0\" was the same as returning true, 0 was true. Sorry about thatAnd thanks Antheus for helping me with the if(pBool) thing :)", "mainEntityOfPage": "https://www.gamedev.net/forums/topic/487180-converting-booleans/" } ] } { "@context": "http://www.schema.org", "@type": "WebSite", "name": "GameDev.net", "url": "https://www.gamedev.net/", "potentialAction": { "type": "SearchAction", "query-input": "required name=query", "target": "https://www.gamedev.net/search/?q={query}" }, "inLanguage": [ { "@type": "Language", "name": "English (USA)", "alternateName": "en-US" } ] } { "@context": "http://www.schema.org", "@type": "Organization", "name": "GameDev.net", "url": "https://www.gamedev.net/", "address": { "@type": "PostalAddress", "streetAddress": "", "addressLocality": null, "addressRegion": null, "postalCode": null, "addressCountry": null } } { "@context": "http://schema.org", "@type": "BreadcrumbList", "itemListElement": [ { "@type": "ListItem", "position": 1, "item": { "@id": "https://www.gamedev.net/groups/", "name": "Groups" } }, { "@type": "ListItem", "position": 2, "item": { "@id": "https://www.gamedev.net/groups/2-for-beginners/", "name": "For Beginners" } }, { "@type": "ListItem", "position": 3, "item": { "@id": "https://www.gamedev.net/forums/forum/71-for-beginners/", "name": "Forum" } } ] } { "@context": "http://schema.org", "@type": "ContactPage", "url": "https://www.gamedev.net/contact/" } Important Information By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.   I accept We are the game development community. Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up! Sign me up!