Basic things I need to know

This is a discussion on Basic things I need to know within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by maxorator What's the difference? Stdio.h automatically includes ctype.h. Where does it say that? What do you mean ...

  1. #31
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by maxorator
    What's the difference? Stdio.h automatically includes ctype.h.
    Where does it say that?

    What do you mean by "man"?
    The Unix man pages.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #32
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by CornedBee
    Where does it say that?
    I can use tolower() when I only include <stdio.h>.

    I don't use UNIX so I don't know about it's man pages.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #33
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by maxorator
    I can use tolower() when I only include <stdio.h>.
    On every compiler that exists? Every compiler that might be written?

    The standard is what counts.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #34
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    So you are saying that <stdio.h> is not a standard header?
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  5. #35
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,434
    No. He's saying that you got it wrong twice. tolower() is defined in <ctype> whether you like it or not. If your compiler implementation has <ctype> included in <stdio.h>, fine. Other implementations may not.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #36
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You mean <ctype.h>, right?

    I don't use UNIX so I don't know about it's man pages.
    On UNIX (or Linux, or Cygwin -- an implementation of bash for Windows), you can generally type
    Code:
    $ man function
    and get information about that function. There are man pages for programs, functions, system calls, etc, divided into 7 sections by type. (For example, printf() has two man pages, for the program and for the function. To access the man page for the function, type man 3 printf.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #37
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,434
    > You mean <ctype.h>, right?

    Yeah. an oversight. Or <cctype> and <cstdio> for all that matters. The point tough being that an implementation is free to decide on how it integrates the several headers. On my implementation #include <iterator> is all I need to use std::string. But that doesn't make it right.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #38
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Well you never answered the first question I posed to you (I'll post an answer soon) but here's another one anyway:

    Code:
    const char * a;
    char const * b;
    char * const c;
    What is the difference (in functionality) between a, b, and c?
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  9. #39
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I can honestly say that I don't know...
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  10. #40
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,434
    Well on the first you create a pointer to a const char. You promise you will not alter the value of a. It is also the only way to create a pointer with the address of a const object.

    The second is the same as the first. It's using one of the shady syntaxes of C++; the const qualifier after the type.

    On the third you create a const pointer to char. You promise you are not going to alter the pointer itself. That is you cannot make it point to something else other than what it was initialized with.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  11. #41
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Quote Originally Posted by maxorator
    I can honestly say that I don't know...
    When you come across situations like this, just remember to read them backwards.

    const char * a;
    "a is a pointer to a character that is constant"

    char const * b;
    "b is a pointer to a constant character"

    char * const c;
    "c is a constant pointer to a character"


    These have to do with:
    * Whether or not you can change the address the pointer contains (i.e. where the pointer is pointing), and
    * Whether or not you can change the contents of the memory the pointer is pointing at.




    a and b are identical, with a being the "normal" syntax and b being an alternative; the pointer is not constant (so you could modify the pointer to point to a new area of memory) but the character(s) that it points to ARE constant. For example:

    a = &x; // This is legal, because you change where a points to (the address that a holds)
    *a = 'A'; // This is illegal because you may not change the contents of the character/string it points to.

    c is the opposite -- you cannot change the address that c holds (the pointer is constant) but you CAN modify the memory at that address:

    c = &x; // Illegal, you're trying to change the address that c holds.
    c[10] = 'C'; // Legal, you can use c to modify the memory it points to.


    You can also do one other kind of pointer:

    const char * const d;
    "d is a constant pointer to a character that is constant"

    In that case, you may not alter the pointer OR the memory it points to.
    Last edited by Cat; 10-13-2006 at 02:50 AM.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  12. #42
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    What's wrong with this?
    Code:
    const char **x;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #43
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,434
    Tricky. Took me a awhile. But I didn't cheat.

    A char** is not actually a pointer to pointer to char. But instead an array of pointers to char. (as we know from one of the main signatures; main(int argc, char **argv)). Being const means the definition needs to be initialized. Const objectsneed to be initialized at the point of declaration. In your example it wasn't.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  14. #44
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    A char** is absolutely a pointer to pointer to char. That pointer to a pointer to a char can be pointing at an array of pointers to char, but there is nothing that says it has to.

    Also, I think that x can be initialized later, so your second point is wrong as well.

  15. #45
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I don't know the exact details, but you can't have a const pointer to a pointer. Perhaps someone can explain why.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

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

Similar Threads

  1. noob with basic q's
    By SimplyComplex in forum C++ Programming
    Replies: 8
    Last Post: 11-19-2006, 12:17 PM
  2. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 09:28 AM
  3. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  4. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 07:41 PM
  5. Basic Window Creation, Dev C++ 4.9.9.0 Linking Error
    By Tronic in forum Windows Programming
    Replies: 2
    Last Post: 11-27-2004, 05:03 PM

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