Issues

This is a discussion on Issues within the C++ Programming forums, part of the General Programming Boards category; the fact that u can do this means ur a pro. the only things i piucked up on was that ...

  1. #16
    I'll take you down! polonyman's Avatar
    Join Date
    Sep 2004
    Posts
    50

    no idea

    the fact that u can do this means ur a pro. the only things i piucked up on was that sumtimes u sed & instead of &&, didn't have #include <iostream> and couldnt see int main(); anywhere. hope it helps!

  2. #17
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    & is the address operator.. most commonly used for storing a variable address into a pointer. && is the 'and' boolean expression.. use mostly for if, if/else, if/else if logical flow control.

    Code:
         double *double_ptr;     //Declare 'double_ptr' as a pointer-type variable
    
         double_ptr = &result;    //Store the address of 'result' into a pointer
    
          cout << *double_ptr;  //Use the '*' dereferrencing operator when you want to see what the pointer points to

    vs. the && and operator
    Code:
    if ((choice == 0) && (result > 0))
    
          answer++;
    Last edited by The Brain; 09-10-2004 at 04:37 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    and couldnt see int main();
    You don't need to prototype main.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    > & is the address operator..
    It is also the bitwise-AND operator, which is similar to the boolean-AND you've already mentioned.

    Code:
    int a = 0x1234;
    a = a & ~0xF;   // lose the bottom 4 bits = 0x1230
    If you write
    Code:
    if ( a & b )
    You wrote
    Code:
    if ( (a & b) != 0 )
    Which is valid to do, and if a and b are boolean, you get the same answer whether you use & or &&.

    The really big difference is that logical operations && and || use short-circuit evaluation, meaning the remainder of the expression is not evaluated if the result is already known.
    Eg.
    Code:
    if ( foo() & bar() ) 
    if ( foo() && bar() )
    In case 1, foo() and bar() will both be called, and it is undefined as to which one is called first. Normal expression evaluation rules apply.
    In case 2, foo() is always called first, and bar() is only called if foo() returned true.

    This means you can test and dereference a pointer in the same expression with perfect safety.
    Code:
    int isNonEmptyString ( char *s ) {
      if ( s != NULL && *s != '\0' )
        return 1;
      else
        return 0;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #20
    Registered User
    Join Date
    Sep 2004
    Posts
    8
    I belive i may have figured out why it doesnt work in 9x systems. 9x stores system files in system instead of system32, somehow I forgot to add the system part in the search, so they were looking for the files in Windows, which of course never existed . I swear i put them in, i really do. Oh Well.

    However, there still is the odd thing that compiling it under XP will cause it to crash in 9x, havent tried it yet, but ill assume it hasnt changed

  6. #21
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Maybe one of the functions you are using is implemented a different way in WinNT and the compiled code therefore is calling a non-existant function on Win9x.

    As to why it would work on both platforms after being compiled on the older Win9x, WinNT needs to be compatible with older software and therefore supports the Win9x method.
    Last edited by Frobozz; 09-10-2004 at 11:26 AM.

  7. #22
    Registered User
    Join Date
    Sep 2004
    Posts
    8
    Quote Originally Posted by Frobozz
    Maybe one of the functions you are using is implemented a different way in WinNT and the compiled code therefore is calling a non-existant function on Win9x.

    As to why it would work on both platforms after being compiled on the older Win9x, WinNT needs to be compatible with older software and therefore supports the Win9x method.

    Im gonna give up on that one, it does now work with the SYSTEM folder addition, and it also does not crash even when compiled on XP, so im just gonna consider it a fluke, since no big code was changed between my last revisions.

  8. #23
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    > if (fileExists("C:/Windows") & fileExists("C:/Winnt"))
    The windows environment variable "windir" tells you the windows installation directory

    Something along the lines of
    Code:
    char *winroot = getenv( "windir" );
    if ( winroot != NULL ) {
    } else {
      // start guessing, or complain
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. iterator issues
    By Elkvis in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2009, 09:52 PM
  2. issues in float division a/b
    By George2 in forum C# Programming
    Replies: 17
    Last Post: 04-24-2008, 07:15 AM
  3. Speed issues
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 04-22-2005, 04:06 AM
  4. Visual Age C++ to MS VC++ conversion issues?
    By Ruchikar in forum Windows Programming
    Replies: 3
    Last Post: 08-10-2003, 10:54 PM
  5. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21