dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: C structs

  1. #1
    Join Date
    Aug 2011
    Posts
    19

    C structs

    Hi, i have a question, say structures are passed into functions by pointer, is it possible to return results to the caller by changing attributes within the structure. If so, why?

    Thanks

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,555

    Re: C structs

    Yes.

    Why not?

  3. #3
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: C structs

    this happens all the time, in fact it is the cornerstone of just about every modern programming

  4. #4
    Join Date
    May 2009
    Posts
    2,413

    Re: C structs

    Quote Originally Posted by aamir121a View Post
    in fact it is the cornerstone of just about every modern programming
    Is it?

    In both object oriented programming and functional programming immutable objects (objects that don't change after creation) are preferred.

  5. #5
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: C structs

    In both object oriented programming and functional programming immutable objects (objects that don't change after creation) are preferred.
    What's the use of object that don't change ? .. or am I missing something ?

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,555

    Re: C structs

    Quote Originally Posted by aamir121a View Post
    this happens all the time, in fact it is the cornerstone of just about every modern programming
    Passing structs to functions and having the function change the struct's values is more a C thing. You wouldn't typically do that in an OOP design, although obviously you can.

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,555

    Re: C structs

    Quote Originally Posted by Skizmo View Post
    What's the use of object that don't change ? .. or am I missing something ?
    I didn't get that either.

  8. #8
    Join Date
    May 2009
    Posts
    2,413

    Re: C structs

    Quote Originally Posted by Skizmo View Post
    What's the use of object that don't change ? .. or am I missing something ?
    You're missing that immutable objects have many advantages. The most prominent is that they're inherently thread-safe but also that they're simple, can be safely shared and won't cause side-effects.

    http://drdobbs.com/architecture-and-design/231000092

    A common OO design rule is that a class should be made immutable unless there's a very good reason not to, and if a class cannot be made fully immutable it should be as immutable as possible. In functional programming immutability is close to law.
    Last edited by nuzzle; November 23rd, 2011 at 02:24 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)