Thread: Simple file close & clear question

  1. #16
    Registered User
    Join Date
    May 2016
    Posts
    40
    Quote Originally Posted by Elysia View Post
    It's OK to do it the longer way if you're uncertain. The basic principle to understand here is that std::stringstream.str() returns a temporary string. Then you call c_str() on that temporary object, giving you a const char* pointer. But when that temporary string goes out of scope, that pointer becomes invalid. What you can generally consider is that temporaries live at least for the duration of the line it was created on. So the example in your link you see someCStyleFunction( myStringStream.str().c_str() ), and this is correct since the temporary string created by str() outlives the function call.

    Now, there is a caveat. The pointer will only live for the function call, or in your code, the constructor call. If the constructor stores away the pointer for later use, it's going to become a problem. However, fstream only needs the pointer to open the file. After that, it doesn't need the pointer any more*, so we're all good.

    *) This is not guaranteed by the standard as far as I know, but I know no sane implementation that would store the pointer because pretty much any OS will give you back a file handle to use to identify the file you've opened.
    Quote Originally Posted by laserlight View Post
    OS considerations aside, a more general implementation issue is that the stream has no guarantees about the lifetime of what the pointer points to either, so if it wants to keep the string, it has to make a copy.
    THANKS (!) to you both for the added insight into this. But just to make sure I understand everything you've said I have just a few more questions on this premise and the logistics thereof.

    (1) If I make any of these calls to initialize a ptr as in,
    const char* p_My_Str = My_SS.str().c_str();

    OR a Parameter as in a Ctor or Function call as in,
    ofstream ofstr_ReVest(ssName.str().c_str());

    OR if I'm getting all this correctly, even in just a single call,
    string My_S;
    My_S = My_SS.str();
    const char* p_My_S = My_S.c_str();

    OR in some compiler settings,
    ofstream ofstr_ReVest(ssName.str());

    In essence the memory of the returned ptrs (or reference) of any of the above calls is valid until the return completion only.
    And whatever stores or grabs that returned ptr needs to immediately copy the value of what's pt'd to, since in the near future depending on happenstance that memory pt'd to may have something different in it. Correct ?

    (2) Also something that confuses me somewhat (at my point of traverse in C++) is when I look at class references of stringstream class I don't see any members, functions or references to the c_str() function. Is the stringstream str() able to call c_str() because of the inheritance thing ? (I'm still learning the aspects of inheritance).

    (3) And not with standing the answer of (2) how would a compiler setting make possible for this, ofstream ofstr_ReVest(ssName.str());
    to happen when the c_str() is just left off. Is this some sort of promoted call or overloaded call ? Sorry if my nomenclature labels are mangled, but hopefully I've gotten the premise of my questions clear.

    (4) And finally is the std::strcpy( .., ..) the same strcopy that I read in some dated articles that everyone stopped using it some yrs back because of it being susceptible to buffer overflow hacks? Seems they were promoting a new strncopy lib or something like that.
    Or is std::strcpy still considered safe to use in code?

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by R_W_B View Post
    In essence the memory of the returned ptrs (or reference) of any of the above calls is valid until the return completion only.
    And whatever stores or grabs that returned ptr needs to immediately copy the value of what's pt'd to, since in the near future depending on happenstance that memory pt'd to may have something different in it. Correct ?
    We need to separate locals and temporaries.
    For example, My_SS.str() returns a temporary. The object returned by this function will be destroyed once the line has finished executing. So if we want to store the object for later use, we have to store it in a local variable, which we can do with:
    auto MyS = My_SS.str();
    MyS will live until the end of the local scope, but the object returned by My_SS.str() will only live until the end of the above line.

    Let's take a break and explain 2):
    (2) Also something that confuses me somewhat (at my point of traverse in C++) is when I look at class references of stringstream class I don't see any members, functions or references to the c_str() function. Is the stringstream str() able to call c_str() because of the inheritance thing ? (I'm still learning the aspects of inheritance).
    A stringstream has no c_str() function. The stringstream returns a temporary std::string object when you call str(). The compiler, in turn, invokes c_str() on this temporary object. If you look at the documentation for std::string, you'll notice it's there. This has nothing to do with inheritance. In pseudo code, you might visualise at as:

    Code:
    auto MyStr = MyStringStream.str();
    auto MyPointer = MyStr.c_str();
    MyStr.Destroy();
    So let's go back to 1). In the above code, you will notice that the temporary string object is destroyed. The memory pointed to by MyPointer belongs to the temporary string object. When it is destroyed, it releases that memory. Accessing freed memory is undefined behaviour - the standard doesn't say what will happen. In practice, you may get an access violation or read some junk or the original data may still be there (but the OS is free to reuse it).

    Therefore,
    Code:
    const char* p_My_Str = My_SS.str().c_str();
    is wrong, because p_My_Str points to freed memory.

    Code:
    ofstream ofstr_ReVest(ssName.str().c_str());
    This is okay, because the memory pointed to by c_str() will only be freed after the current line has finished executing because that's when the temporary string created will be destroyed.

    Code:
    string My_S;
    My_S = My_SS.str();
    const char* p_My_S = My_S.c_str();
    This is also okay because My_S is a local variable and will only be destroyed when the local scope ends.

    Code:
    ofstream ofstr_ReVest(ssName.str());
    This is also okay because the temporary returned string object will be alive until the end of the line.

    (3) And not with standing the answer of (2) how would a compiler setting make possible for this, ofstream ofstr_ReVest(ssName.str());
    to happen when the c_str() is just left off. Is this some sort of promoted call or overloaded call ? Sorry if my nomenclature labels are mangled, but hopefully I've gotten the premise of my questions clear.
    fstream have an overloaded constructor that takes an std::string.

    (4) And finally is the std::strcpy( .., ..) the same strcopy that I read in some dated articles that everyone stopped using it some yrs back because of it being susceptible to buffer overflow hacks? Seems they were promoting a new strncopy lib or something like that.
    Or is std::strcpy still considered safe to use in code?
    std::strcpy is fine if you use it right. But that's risky since one tend to make mistakes. std::strncpy is just another version that says copy max N characters. It's safer than std::strcpy, but just as unsafe if you pass in the incorrect arguments. It is much safer to simply use std::string.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    May 2016
    Posts
    40
    Quote Originally Posted by Elysia View Post
    We need to separate locals and temporaries.
    For example, My_SS.str() returns a temporary. The object returned by this function will be destroyed once the line has finished executing. So . . . . . .< cut out > . . . . . . .
    Well that's was an excellent explanation on the premises involved. When you say "only live until the end of the line of code" that kinda kicks it up a notch. In other words it has to be returned to something with some sort of lifetime. I.e. at least a local. And not just initializing a ptr with the address of the temporary object with the hopes of copying the temporary value after the fact. While I surmise an app recalling the same str() or c_str() would be culprit of changing said temporary contents, the fact is after the line of code ends, all bets are off.

    I also see how saving the return from str() to a local string of my creation will do such and also then initializing a local char* ptr pointing to that local with the return to c_str().

    But I haven't been able to see any code where the ofstream object does that with either the,
    ofstream ofstr_ReVest(ssName.str().c_str());
    or
    ofstream ofstr_ReVest(ssName.str());

    I understand it's probably all private and I don't need to understand it, but it made me paranoid of trusting it to do so. Of course I surmise it must or it would be negligent in accepting returns pointing to temporaries. So I will just take that for granted.

    And that brings me to the compiler involvement. Where you said "A stringstream has no c_str() function. The stringstream returns a temporary std::string object when you call str(). The compiler, in turn, invokes c_str() on this temporary object. If you look at the documentation for std::string, you'll notice it's there."

    Yes I've seen the c_str() in std::string. But this thing of the compiler calling something outside the class on it's own is a bit confusing to me. I'm guessing you mean both the
    ofstream ofstr_ReVest(ssName.str().c_str());
    and the
    ofstream ofstr_ReVest(ssName.str()); scenarios both (?) or at least with c++11 anyhow.

    Or even when the programmer writes the .str().c_str() is confusing to me since c_str() is not even listed in the stringstream class, even as a non-memberf function. To me that doesn't look like the same thing as two function calls with one catching the return of the other. To me it looks like accessing a nested struct member, but that's beside the facet at this point.

    This just goes right over my head and I will have to keep studying the books cause I don't quite get it at this point. However I can conceive of the streams having an overloaded operator to take a std::string, or even doing something with auto (post c++11). But really struggling to conceptualize the compiler just knowing a null terminator is needed on the return string to ofstream's filename, therein calling c_str(). Or possibly I missed that read in your post and it's not, but rather code within the ofstream overloads that's dealing with it?

    But I thank you for your input it has helped me in my journey.

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by R_W_B View Post
    I also see how saving the return from str() to a local string of my creation will do such and also then initializing a local char* ptr pointing to that local with the return to c_str().

    But I haven't been able to see any code where the ofstream object does that with either the,
    ofstream ofstr_ReVest(ssName.str().c_str());
    or
    ofstream ofstr_ReVest(ssName.str());

    I understand it's probably all private and I don't need to understand it, but it made me paranoid of trusting it to do so. Of course I surmise it must or it would be negligent in accepting returns pointing to temporaries. So I will just take that for granted.
    I mentioned temporaries live until the end of the line. The end of the line is after the function call, so the temporary lives all the way through the function call, making it safe.

    And that brings me to the compiler involvement. Where you said "A stringstream has no c_str() function. The stringstream returns a temporary std::string object when you call str(). The compiler, in turn, invokes c_str() on this temporary object. If you look at the documentation for std::string, you'll notice it's there."

    Yes I've seen the c_str() in std::string. But this thing of the compiler calling something outside the class on it's own is a bit confusing to me. I'm guessing you mean both the
    ofstream ofstr_ReVest(ssName.str().c_str());
    and the
    ofstream ofstr_ReVest(ssName.str()); scenarios both (?) or at least with c++11 anyhow.

    Or even when the programmer writes the .str().c_str() is confusing to me since c_str() is not even listed in the stringstream class, even as a non-memberf function. To me that doesn't look like the same thing as two function calls with one catching the return of the other. To me it looks like accessing a nested struct member, but that's beside the facet at this point.
    You need to see it from the view of the compiler.
    Semantically, in the language's viewpoint, this line

    ofstream ofstr_ReVest(ssName.str().c_str());

    can be written in pseudo code as:

    std::string tmp = ssName.str();
    const char* tmp2 = tmp.c_str();
    ofstream ofstr_ReVest(tmp2);
    tmp2.Destroy();
    tmp.Destroy();

    This just goes right over my head and I will have to keep studying the books cause I don't quite get it at this point. However I can conceive of the streams having an overloaded operator to take a std::string, or even doing something with auto (post c++11). But really struggling to conceptualize the compiler just knowing a null terminator is needed on the return string to ofstream's filename, therein calling c_str(). Or possibly I missed that read in your post and it's not, but rather code within the ofstream overloads that's dealing with it?
    c_str() is guaranteed to return a C-style string. That means there is a guaranteed null terminator in the string it returns. c_str() does the work; ofstream is oblivious to this fact.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    May 2016
    Posts
    40
    Quote Originally Posted by Elysia View Post
    I mentioned temporaries live until the end of the line. The end of the line is after the function call, so the temporary lives all the way through the function call, making it safe.
    Yes, I understood that, but I did not know that ofstream is doing that (at the end of the call). But it would appear it does so I will accept that.

    Quote Originally Posted by Elysia View Post
    You need to see it from the view of the compiler.
    Semantically, in the language's viewpoint, this line

    ofstream ofstr_ReVest(ssName.str().c_str());

    can be written in pseudo code as:

    std::string tmp = ssName.str();
    const char* tmp2 = tmp.c_str();
    ofstream ofstr_ReVest(tmp2);
    tmp2.Destroy();
    tmp.Destroy();
    It's not hard for me to imagine either ofstream or the compiler doing this (if the compiler was coded with knowledge of what is going on in a given lib call). I just would have thought that it would be up to ofstream to do it (with whatever args it's operators are coded to deal with). And the compiler's job to compile it as written.
    I don't mean to split hairs but in my ignorance of learning stage, it just seems that the compiler's job is only to compile the program code, include code, and lib code as it is written.
    The idea of the compiler making decisions on calls to any given lib "other than" simply compiling said lib's code for the call, is a alien and new to me.
    Evidently a given compiler is privy to it's libs code in a more involved way than I perceived before.

    Quote Originally Posted by Elysia View Post
    c_str() is guaranteed to return a C-style string. That means there is a guaranteed null terminator in the string it returns. c_str() does the work; ofstream is oblivious to this fact.
    Yes I understood that part, I surmise my rambling diluted that. But what confused me was the compiler just knowing a null terminator was needed on the return. I mean if I know it, I could probably (even in my newb state) come up with a way to add the null in. But again I would have thought that would be the job of the caller and it's operators to deal with. Or if the returned argument was not in proper type etc, then an error on compile and then the programmer would have to solve it.

    But as always I thank you MUCH for all your diligent advice and direction. It has helped light my way through what was once total darkness, now I'm just kinda drifting in the light but still not to the harbor, even with your lighthouse help.

    I'm doing a partition backup right after I get off here and then I will download Visual Studio Community and install it tomorrow. Hopefully it will come with source code that I can step fully into with the debugger and actually see what ofstream etc is doing. My DevC only shows assembler with no source labels. That should satisfy my curiousity in these matters. Meanwhile I will continue to attempt to learn the c++ language and libs. It is a very interesting hobby of late for me.

  6. #21
    Registered User
    Join Date
    Jul 2016
    Posts
    5
    If I can try to clear up what I think may be some confusion here.

    Quote Originally Posted by R_W_B View Post
    Or even when the programmer writes the .str().c_str() is confusing to me since c_str() is not even listed in the stringstream class, even as a non-memberf function.
    If we have a std::stringstream like this:

    Code:
    std::stringstream ss;
    Then when the programmer calls its .str() function it returns a std::string object:

    Code:
    ss.str(); // this returns a std::string, any further operations will be on that std::string
    So when we get to the final call .c_str() that function is called on the returned std::string object.

    Code:
    ss.str().c_str(); // this returns a const char* from the std::string that was produced by the str() call to the std::stringstream
    Quote Originally Posted by R_W_B View Post
    To me that doesn't look like the same thing as two function calls with one catching the return of the other.
    But that is exactly what it is.

    Quote Originally Posted by R_W_B View Post
    To me it looks like accessing a nested struct member, but that's beside the facet at this point.
    Well there is a reason it looks the same because it sort of is. Only instead of accessing member variables you are accessing member functions.

    Consider this:

    Code:
    struct MyStruct
    {
        std::string s;
    
        std::string func() { return "whatever"; }
    };
    
    MyStruct ms;
    
    ms.s.size(); // access member variable s which is of type std::string and call the returned std::string's size() function
    
    ms.func().size(); // access member function func() which is of type std::string and call the returned std::string's size() function
    There is a direct analogy between accessing member variables and member functions.

    Quote Originally Posted by R_W_B View Post
    But really struggling to conceptualize the compiler just knowing a null terminator is needed on the return string to ofstream's filename, therein calling c_str().
    The compiler doesn't know this you told it when you said ss.str().c_str();

    You told the compiler to call ss.str() and with the returned std::string to call .c_str() upon that string.



    196219224270272277
    Last edited by Galik; 07-17-2016 at 12:17 AM.

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by R_W_B View Post
    Yes, I understood that, but I did not know that ofstream is doing that (at the end of the call). But it would appear it does so I will accept that.
    ofstream doesn't do anything. The compiler creates and destroys the temporaries. This is just how the language works. The same happens whether you try to call ofstream or any other function. No magic involved. The compiler does not know what the functions or constructors do. It only knows that you are calling a function that returns something and it needs to pass that something to the function or constructor. Therefore, it needs to create a temporary.

    It's not hard for me to imagine either ofstream or the compiler doing this (if the compiler was coded with knowledge of what is going on in a given lib call). I just would have thought that it would be up to ofstream to do it (with whatever args it's operators are coded to deal with). And the compiler's job to compile it as written.
    I don't mean to split hairs but in my ignorance of learning stage, it just seems that the compiler's job is only to compile the program code, include code, and lib code as it is written.
    The idea of the compiler making decisions on calls to any given lib "other than" simply compiling said lib's code for the call, is a alien and new to me.
    Evidently a given compiler is privy to it's libs code in a more involved way than I perceived before.
    No, not at all. The compiler does NOT know what the library does. This is the semantic meaning of how you wrote the code. The language (C++) says t hat if you write something like "obj1.foo().bar()", then the generated code shall look like this. It has nothing to do with ofstream.

    Yes I understood that part, I surmise my rambling diluted that. But what confused me was the compiler just knowing a null terminator was needed on the return. I mean if I know it, I could probably (even in my newb state) come up with a way to add the null in. But again I would have thought that would be the job of the caller and it's operators to deal with. Or if the returned argument was not in proper type etc, then an error on compile and then the programmer would have to solve it.
    The c_str() function adds in the null terminator. The compiler does. The compiler doesn't even know it's necessary because it does not know what the functions does or what they accept. Again, this is because you're calling c_str() on the temporary string object and the c_str() function's job is to add a null terminator if one is missing and returns a C-style string of its internal string contents.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User
    Join Date
    May 2016
    Posts
    40
    ->Originally Posted by R_W_B, " To me that doesn't look like the same thing as two function calls with one catching the return of the other."-<

    Quote Originally Posted by Galik View Post
    If I can try to clear up what I think may be some confusion here. . . . . . . . .
    . . . . . . .
    Code:
    ss.str().c_str(); // this returns a const char* from the std::string that was produced by the str() call to the std::stringstream
    But that is exactly what it is.

    ->Originally Posted by R_W_B, " . . . when the programmer writes the .str().c_str() is confusing to me since c_str() is not even listed in the stringstream class, even as a non-memberf function. "<-

    Well there is a reason it looks the same because it sort of is. Only instead of accessing member variables you are accessing member functions.

    Consider this:

    Code:
    struct MyStruct
    {
        std::string s;
    
        std::string func() { return "whatever"; }
    };
    
    MyStruct ms;
    
    ms.s.size(); // access member variable s which is of type std::string and call the returned std::string's size() function
    
    ms.func().size(); // access member function func() which is of type std::string and call the returned std::string's size() function
    There is a direct analogy between accessing member variables and member functions.

    The compiler doesn't know this you told it when you said ss.str().c_str();

    You told the compiler to call ss.str() and with the returned std::string to call .c_str() upon that string.
    196219224270272277
    Ok I'm down with that totally, never was confused on that premise specifically. The part that's confusing me is that the c_str() [ of the ss.str().c_str() ] is not a member or variable of ss.

    Quote Originally Posted by Elysia View Post
    ofstream doesn't do anything. The compiler . . . . . . . . . .
    This is the semantic meaning of how you wrote the code. The language (C++) says t hat if you write something like "obj1.foo().bar()", then the generated code shall look like this. It has nothing to do with ofstream.

    The c_str() function adds in the null terminator. The compiler does. The compiler doesn't even know it's necessary because it does not know what the functions does or what they accept. Again, this is because you're calling c_str() on the temporary string object and the c_str() function's job is to add a null terminator if one is missing and returns a C-style string of its internal string contents.
    Ok, I understand what you are saying, just still rationalizing it in my mind. At my stage of learning it almost sounds like if I have a function in a class called OneClass that is called,
    OneClass::1Cls()

    and I have another function in another class called TwoClass (not a member function or inherited or friend etc of OneClass) that is called,
    TwoClass::2Cls().

    Then I can just write
    OneClass MyOneCls;
    TwoClass MyTwoCls;

    WhateverCondusiveClassObj(MyOneCls.1Cls().My2Cls() ;

    Please point out where that above analogy is not synonymous with what your trying to show me (syntactically or otherwise) and I surmise that will unlock my vision in this. And if the above is synonymous with your instruction then I surmise this is just C++'s syntax way of doing what the old C way of,

    FuncThis(FuncFinalReturn(FuncFirstReturn() ) );

    I obviously have some sort of preconceived concept in this that's blocking my grasp of this.

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This is sufficient:

    OneClass MyOneCls;
    WhateverCondusiveClassObj(MyOneCls.1Cls().My2Cls() );

    Assume that a class member function MyClass::foo(T) (where T is any kind of type) is equivalent to a non-member function (MyObj* this, T). This is close to how it looks in assembly.
    Now assume we have two classes: MyClass1, MyClass2.
    Further assume we have the member functions:

    MyClass2 MyClass1::foo()
    void MyClass2::bar()

    In C terms, they would look like:

    MyClass2 foo(MyClass1* this);
    void bar(MyClass2* this);

    Then, when we do

    MyClass1 var;
    var.foo().bar();

    Then what we're doing in C terms is:

    bar(foo(&var));
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #25
    Registered User
    Join Date
    Jul 2016
    Posts
    5
    Quote Originally Posted by R_W_B View Post
    The part that's confusing me is that the c_str() [ of the ss.str().c_str() ] is not a member or variable of ss.
    Maybe this will clarify things.

    When you have this:
    Code:
    ss.str().c_str();
    The compiler creates its own temporary variables as necessary to do the rough equivalent of this:

    Code:
    std::string temp1 = ss.str();
    const char* temp2 = temp1.c_str();
    But it does it all 'in place' so the result (temp2) lasts until the end of the expression. So if ss.str().c_str() is used as a parameter to a function, the function completes execution before the temporaries are destroyed.
    706712722

  11. #26
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    The part that's confusing me is that the c_str() [ of the ss.str().c_str() ] is not a member or variable of ss.
    The c_str() function is not a member of the stringstream class, it is a member function of the string class.

    So perhaps you need to stop trying to combine all the operations on one line.

    Code:
    ...  // You already have a stringstreamm (ss) holding the desired information.
        std::string temp; // Create a temporary string.
        temp = ss.str(); // Convert the stringstream to the temporary string.
        char temp_c_string[1000]; // Create a temporary C-string.
        strcpy(temp_c_string, temp.c_str()); // Copy the string to the C-string.

    Jim

  12. #27
    Registered User
    Join Date
    May 2016
    Posts
    40
    Quote Originally Posted by Elysia View Post
    This is sufficient:

    OneClass MyOneCls;
    WhateverCondusiveClassObj(MyOneCls.1Cls().My2Cls() );

    Assume that a class member function MyClass::foo(T) (where T is any kind of type) is equivalent to a non-member function (MyObj* this, T). This is close to how it looks in assembly.
    Now assume we have two classes: MyClass1, MyClass2.
    Further assume we have the member functions:

    MyClass2 MyClass1::foo()
    void MyClass2::bar()

    In C terms, they would look like:

    MyClass2 foo(MyClass1* this);
    void bar(MyClass2* this);

    Then, when we do

    MyClass1 var;
    var.foo().bar();

    Then what we're doing in C terms is:

    bar(foo(&var));
    Ok I see the syntax as an allowed reality now. I've read 1 and 1/2 C++ books so far and somehow I do not ever remember running across that syntax for functions returning to functions. If it was there then I missed it. And further complicating my mind was that I had seen such in struct or class member access.
    I think finally you guys have showed me what I was missing. I apologize for any ambiguity in my questions. You've been a great help in this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question about file I/O.
    By The7thCrest in forum C++ Programming
    Replies: 2
    Last Post: 02-04-2009, 05:15 PM
  2. simple file I/O question
    By loopshot in forum C Programming
    Replies: 2
    Last Post: 11-30-2006, 02:59 PM
  3. simple File I/O question
    By bobnet in forum C++ Programming
    Replies: 4
    Last Post: 10-25-2003, 06:53 AM
  4. FYI - a simple way to clear the screen
    By johnc in forum C Programming
    Replies: 13
    Last Post: 07-17-2002, 04:53 PM
  5. Replies: 8
    Last Post: 11-21-2001, 12:13 AM

Tags for this Thread