pls post here tricks that you know of in C/C++, thanks

This is a discussion on pls post here tricks that you know of in C/C++, thanks within the C++ Programming forums, part of the General Programming Boards category; I know that on some compilers, if there is no explicit return statement, then it will just return the last ...

  1. #46
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I know that on some compilers, if there is no explicit return statement, then it will just return the last value that was calculated. I wasn't sure if it was standard or not.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  2. #47
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    Hi guys,

    please please, i beg you, do not post your tips and tricks here and instead, post it on my website,

    my collection of tips and tricks

    please... thanks
    http://www.angrysoft.com/
    Get SMS Counter and Call Counter for Nokia 7650/3650

    http://www.angrysoft.com/tipsandtricks.php
    Please contribute some tips and tricks that you know of.

  3. #48
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    Originally posted by XSquared
    I know that on some compilers, if there is no explicit return statement, then it will just return the last value that was calculated. I wasn't sure if it was standard or not.
    Not to my knowledge. In assembly it's just easier, so some compilers defaulted to that. Since the value is in the register already, that's one less step in preparing the stack for a function call.

  4. #49
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    OK. Edited my code to add a return statement.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #50
    volkinythe
    Guest
    Originally posted by mickey
    Hi guys,

    please please, i beg you, do not post your tips and tricks here and instead, post it on my website,

    my collection of tips and tricks

    please... thanks
    Nah, it's better to post them here - where everyone can benefit. There's really no incentive to go to your website, anyway.

    You could just copy and paste the "tips and tricks", no?

  6. #51
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Originally posted by prophet
    Last thing I've noticed and I already made a post about this is the following problem on BCC and g++. Don't know what other compilers are affected but I know VC++ does it correctly (ironic).

    Code:
    void main() {
    
      int *arr = new int[10];
    
      arr[5] = 3;
    
      cout << "Before: " << arr[5] << endl;//prints out 3
      delete[] arr; //deletes the array from memory
      cout << "After: " << arr[5] << endl; //prints out 3
    I was under the impression that delete works pretty much instantaneously and that is what the benefits of using dyanamic arrays were for, to save memory. If it didn't work instantaneously then it would more than likely return the memory at the END of the program which would mean that it takes up memory as much as static arrays. Obviously I could be wrong about this but, that was the impression I got from reading about it. Also I'm getting too used to Java's garbage collecting feature in the compiler which handles that stuff for you =)
    I can explain this one for you. Delete acts instantly. That memory is no longer assigned to your program, and could change at any time. But you still have a pointer to it, because you haven't changed the pointer's value (you should always change it to NULL after you delete to avoid this problem). Delete just means that the memory isn't assigned to your program anymore - it doesn't clear the contents of the RAM there. So, you're couting the data in that location of the RAM, but it doesn't belong to your program and won't *necessarily* be what you think it will be. It's the same reason that you should initialize your pointers to NULL and your variables to some value before you use them...there's junk data there until then.
    Away.

  7. #52
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    Originally posted by blackrat364
    Delete just means that the memory isn't assigned to your program anymore - it doesn't clear the contents of the RAM there.
    is that right? wow, but it's still there, just ready to be overwritten eh?

    anyway, i am still hoping that you guys could transfer your tips and tricks to my page:

    http://www.angrysoft.com/tipsandtricks.php
    http://www.angrysoft.com/
    Get SMS Counter and Call Counter for Nokia 7650/3650

    http://www.angrysoft.com/tipsandtricks.php
    Please contribute some tips and tricks that you know of.

  8. #53
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    yeah, try this... well, actually, don't, but you can if you want.

    Code:
    int a;
    cout<<a;
    You'll get some junk value there, or a crash, or something to tell you you're doing something incorrectly.

    Code:
    int *a;
    a=new int[23423];
    just gives you a lot of junk....

    Code:
    int *a=/*some arbitrary memory address hard coded*/
    You've just given yourself a pointer to...who knows what. There will be data there, though. It might be yours. It might not be. But you could definitely output it...

    Here's the lesson boys and girls, and a great tip for all:
    Initialize your pointers to null, and reset them to null after you delete
    Away.

  9. #54
    Registered User
    Join Date
    Apr 2002
    Posts
    142
    alright guys,

    i might as well be the one to transfer the tips and tricks on this forum if you guys don't want to.
    http://www.angrysoft.com/
    Get SMS Counter and Call Counter for Nokia 7650/3650

    http://www.angrysoft.com/tipsandtricks.php
    Please contribute some tips and tricks that you know of.

  10. #55
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    Originally posted by vVv

    > Here's the lesson boys and girls, and a great tip for all:

    Mere misinformation, such as the assumption that you can accidently access other processes' address spaces, is definitely not a lesson.
    Actually, I believe the lesson he was referring to was:

    >>Initialize your pointers to null, and reset them to null after you delete

    He even put it in bold. And that colon after the word "all" was also a good clue.


    Originally posted by mickey
    alright guys,

    i might as well be the one to transfer the tips and tricks on this forum if you guys don't want to.
    Yeah, you sure might as well be "the one." Don't be sad, though. As long as you get those nifty tricks, you should be fine.

  11. #56
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    Originally posted by vVv
    > Actually, I believe the lesson he was referring to was:

    I know very well what he was referring to, it's just my wording that might have been misleading. How about:


    Mere misinformation, such as the assumption that you can accidently access other processes' address spaces, is definitely not an argument to make a ``lesson'' any more credible.


    It's still butchered, but you get what I mean (hopefully).
    That's more like it, ``vVv."

    Well...actually...ok, I'll stop.

    Anyway, it wasn't just your wording, you actually quoted:

    > Here's the lesson boys and girls, and a great tip for all:

    In any case, take care, kid.

Page 4 of 4 FirstFirst 1234
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 05:15 PM
  2. C programming - pls pls help me
    By sally arnold in forum C Programming
    Replies: 10
    Last Post: 01-16-2002, 04:55 AM
  3. pls help me!!
    By hanseler in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2001, 08:46 PM
  4. Pls Help Me In This Question!!!
    By Joanna in forum Windows Programming
    Replies: 1
    Last Post: 10-20-2001, 03:05 PM
  5. 40 post drop
    By gamegod3001 in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-12-2001, 01:14 PM

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