Thread: Basic things I need to know

  1. #16
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Quote Originally Posted by maxorator
    zx-1, the second one works with 16bit, 32bit and 64bit Unicode versions too.
    Nope. That'd be with sizeof(wchar_t), assuming there's a difference between wide and and narrow chars.
    Last edited by zx-1; 10-09-2006 at 06:23 AM.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  2. #17
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I see no differences then because sizeof(char) is always 1 byte.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #18
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by Queatrix
    So much for inactive.
    Actually it was midnight. I just thought I'd look if there's something interesting here before I went to sleep.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #19
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    Quote Originally Posted by maxorator
    I see no differences then because sizeof(char) is always 1 byte.
    That's 95% correct. There is a difference, albeit a somewhat esoteric one.
    It was really kind of a trick question. :-)
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  5. #20
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Hmm, you can define char to be something else?
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #21
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    No. Answer:
    8192 is the same as (int)8192.
    8192 * sizeof(char) is the same as (size_t)8192.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I assert that porting legacy code is the only valid reason for having "using" in your code. It decreases readability; putting std:: in front of everything makes it far more clear what's going on.
    I think that this is another valid use of "using":
    Code:
    void ClassName::swap(ClassName& x) {
        using std::swap;
        swap(member1, x.member1);
        swap(member2, x.member2);
    }
    At the initial point when the code was written, it is possible that the types of member1 and member2 do not yet have their own (presumably optimised) swap functions. As such, the standard swap algorithm would be used. At some later point, this might change, and thus a re-compile should have ClassName::swap pick up the optimisations automatically.

    Here is another valid use of "using":
    Code:
    #include <iostream>
    
    class Base {
    public:
        void memberFunction() {
            std::cout << "Base::memberFunction()" << std::endl;
        }
    
        virtual void memberFunction(int num) {
            std::cout << "Base::memberFunction(" << num << ")" << std::endl;
        }
    };
    
    class Derived : public Base {
    public:
        using Base::memberFunction;
        virtual void memberFunction(int num) {
            std::cout << "Derived::memberFunction(" << num << ")" << std::endl;
        }
    };
    
    int main() {
        Derived x;
        x.memberFunction();
    }
    If the "using Base::memberFunction;" was commented out, there would be a compile error, since Derived::memberFunction(int) hides the name "memberFunction" in the Base class' scope. As such, a call to Base::memberFunction() from x would be invalid.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    I think Cat was referring to the using statement, not the using declaration. But far be it from me to place words in his mouth

    zx-1: it actually took me two looks on your code to find the difference. Very nice example.

    maxorator: no, but you need to learn good design.
    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

  9. #24
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Well, I see the difference too, one of them is shorter than the other one.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  10. #25
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    4. In C, it is in the <string.h> library.
    Look again.
    6. Do you mean kind of overload the template with a template function that has parameters types specified, so when those types are used in the function, that function template is used?
    I mean that you can have a generic template class, like vector<>, but also a specialized version, such as vector<bool>, which has a slightly different behaviour.
    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.

  11. #26
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    What should you do if you detect an error while in a constructor? What about a destructor? Why is auto_ptr<> not appropriate for holding pointers that will be stored in standard containers? What is a good alternative? What is the airspeed velocity of an unladen swallow? Is that airspeed sufficient to carry a coconut?
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  12. #27
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Look again.
    Oh, sorry, accidentally compiled it as C++, stdio.h of course.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  13. #28
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    The question: What header file is tolower() in?
    Quote Originally Posted by maxorator
    [...] stdio.h of course.
    Wrong! Better start using your grepping power.
    Last edited by whiteflags; 10-10-2006 at 12:38 PM. Reason: Needed more Luthor

  14. #29
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Third time lucky.
    Better start using your grepping power.
    Or man tolower or google("site:cppreference.com tolower") or countless other ways.
    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.

  15. #30
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    What's the difference? Stdio.h automatically includes ctype.h.
    What do you mean by "man"?
    "The Internet treats censorship as damage and routes around it." - John Gilmore

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, 01:17 PM
  2. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10: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, 08: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, 06:03 PM