c can protect the data in struct

Discussion in 'C Programming' started by satheesh, Feb 27, 2008.

  1. satheesh

    satheesh Guest

    c language can protect the data in scopes private,protected and
    public(may be) in structure and union?
     
    satheesh, Feb 27, 2008
    #1
    1. Advertising

  2. satheesh

    santosh Guest

    satheesh wrote:

    > c language can protect the data in scopes private,protected and
    > public(may be) in structure and union?


    No it can't. It can be hidden from direct access from an outer scope or
    from another translation unit, but nothing anywhere in a C program's
    address space can be absolutely protected from any other part of
    itself.

    Maybe you can clarify your question?
     
    santosh, Feb 27, 2008
    #2
    1. Advertising

  3. satheesh

    satheesh Guest

    On Feb 27, 6:35 pm, santosh <> wrote:
    > satheesh wrote:
    > > c language can protect the data in scopes private,protected and
    > > public(may be) in structure and union?

    >
    > No it can't. It can be hidden from direct access from an outer scope or
    > from another translation unit, but nothing anywhere in a C program's
    > address space can be absolutely protected from any other part of
    > itself.
    >
    > Maybe you can clarify your question?


    yes.
    c++ having the data abstraction like protect, private.
    c structure writes with protect, private also.
    example:
    struct bio
    {
    protect int a,b;
    public:
    void read()
    void display()
    };
    what is the different between the c structure's protected, private and
    c++ class's protected, private.
     
    satheesh, Feb 27, 2008
    #3
  4. On Feb 27, 8:47 am, satheesh <> wrote:
    > On Feb 27, 6:35 pm, santosh <> wrote:
    >
    > > satheesh wrote:
    > > > c language can protect the data in scopes private,protected and
    > > > public(may be) in structure and union?

    >
    > > No it can't. It can be hidden from direct access from an outer scope or
    > > from another translation unit, but nothing anywhere in a C program's
    > > address space can be absolutely protected from any other part of
    > > itself.

    >
    > > Maybe you can clarify your question?

    >
    > yes.
    > c++ having the data abstraction like protect, private.
    > c structure writes with protect, private also.
    > example:
    > struct bio
    > {
    >    protect int a,b;
    >    public:
    >    void read()
    >    void display()};
    >
    > what is the different between the c structure's protected, private and
    > c++ class's protected, private.


    I did a search of private/ protected in ISO/IEC 9989 but did not find
    anything. Where did u see this?

    Suresh M. Shenoy
     
    suresh shenoy, Feb 27, 2008
    #4
  5. satheesh

    santosh Guest

    satheesh wrote:

    > On Feb 27, 6:35 pm, santosh <> wrote:
    >> satheesh wrote:
    >> > c language can protect the data in scopes private,protected and
    >> > public(may be) in structure and union?

    >>
    >> No it can't. It can be hidden from direct access from an outer scope
    >> or from another translation unit, but nothing anywhere in a C
    >> program's address space can be absolutely protected from any other
    >> part of itself.
    >>
    >> Maybe you can clarify your question?

    >
    > yes.
    > c++ having the data abstraction like protect, private.
    > c structure writes with protect, private also.
    > example:
    > struct bio
    > {
    > protect int a,b;
    > public:
    > void read()
    > void display()
    > };
    > what is the different between the c structure's protected, private and
    > c++ class's protected, private.


    Your code is *not* C. It is probably C++, which treats struct and class
    as essentially the same, or perhaps some proprietary dialect of C.

    There are no keywords like 'public', 'protected' or 'private' in C. Try
    comp.lang.c++
     
    santosh, Feb 27, 2008
    #5
  6. satheesh

    satheesh Guest

    i studied in trichy LINSOFT. He teach this program.
     
    satheesh, Feb 27, 2008
    #6
  7. satheesh

    santosh Guest

    satheesh wrote:

    > i studied in trichy LINSOFT. He teach this program.


    Well, he (or it) taught you wrong then. See the following document for
    the best authoritative definition of the C language short of actually
    buying the ISO Standard for it.

    <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf>
     
    santosh, Feb 27, 2008
    #7
  8. satheesh

    Randy Howard Guest

    On Wed, 27 Feb 2008 08:00:34 -0600, satheesh wrote
    (in article
    <>):

    > i studied in trichy LINSOFT. He teach this program.


    "He" is wrong. C does not have these features. Compiling code that is
    /claimed/ to be C with a C++ compiler doesn't make it true.


    --
    Randy Howard (2reply remove FOOBAR)
    "The power of accurate observation is called cynicism by those
    who have not got it." - George Bernard Shaw
     
    Randy Howard, Feb 27, 2008
    #8
  9. satheesh

    Eric Sosman Guest

    satheesh wrote:
    > c language can protect the data in scopes private,protected and
    > public(may be) in structure and union?


    C has no "private" or "protected" or "public" scope.
    Are you thinking of some other language?

    --
    Eric Sosman
    lid
     
    Eric Sosman, Feb 27, 2008
    #9
  10. satheesh <> writes:
    > On Feb 27, 6:35 pm, santosh <> wrote:
    >> satheesh wrote:
    >> > c language can protect the data in scopes private,protected and
    >> > public(may be) in structure and union?

    >>
    >> No it can't. It can be hidden from direct access from an outer scope or
    >> from another translation unit, but nothing anywhere in a C program's
    >> address space can be absolutely protected from any other part of
    >> itself.
    >>
    >> Maybe you can clarify your question?

    >
    > yes.
    > c++ having the data abstraction like protect, private.
    > c structure writes with protect, private also.
    > example:
    > struct bio
    > {
    > protect int a,b;
    > public:
    > void read()
    > void display()
    > };
    > what is the different between the c structure's protected, private and
    > c++ class's protected, private.


    Both C and C++ have "struct" types. A C struct declaration is very
    likely to be a valid C++ struct declaration, but not vice versa;
    *some* C++ struct declarations are valid C struct declarations, but
    not all.

    <OT>
    In C++, the only difference between a struct and a class is that
    struct members are public by default, and class members are private by
    default. Either a struct or a class can use all the C++-specific
    features that don't exist in C; public, private, protected, member
    functions, inheritance, etc. But as a matter of C++ programming
    style, the usual convention is to use the "struct" keyword for the
    relatively simple types that would also be valid in C, and the "class"
    keyword for types that depend on C++-specific features. The reasons
    for this rather odd state of affairs are rooted in the history of the
    C++ language, which is very much off-topic here. For more C++
    information, read a good C++ textbook, or the C++ FAQ at
    <http://www.parashift.com/c++-faq-lite/>, or post to comp.lang.c++ or
    comp.lang.c++.moderated.
    </OT>

    (The "OT" tags above mean "off-topic", indicating that discussions of
    C++ are generally in appropriate here in comp.lang.c. I'm making an
    exception here because the point is to illustrate something about C.)

    So your type "struct bio", though it's a valid declaration in C++ (or
    would be if fixed a few syntax errors), really should have been
    declared as a class, not as a struct. As I said, *some* C++
    declarations are also valid C declarations; your "struct bio" is not.
    It's not the "struct" keyword that a C++ type valid in C; it's the
    features used within it (the stuff between the curly braces). Try
    feeding your declaration to a C compiler, and you'll see what I mean
    (here gcc is acting as a C compiler, and g++ is a C++ compiler):

    % cat bio.c
    struct bio {
    protected:
    int a, b;
    public:
    void read();
    void display();
    };
    % g++ -c bio.c
    % gcc -c bio.c
    bio.c:2: error: parse error before "protected"
    bio.c:2: warning: no semicolon at end of struct or union
    bio.c:7: error: parse error before '}' token

    (The warning about the missing semicolon is spurious; compilers are
    often confused by syntax errors.)

    And keep in mind that, in spite of their superficial similarities, C
    and C++ are really two different languages, and should (almost always)
    be treated as such.

    --
    Keith Thompson (The_Other_Keith) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Feb 27, 2008
    #10
  11. >c language can protect the data in scopes private,protected and
    >public(may be) in structure and union?


    No. There are no scopes private, protected and public in C.

    You are looking for C++. And C++ cannot really protect (as in
    prevent access) either. The protection only works if everyone obeys
    the rules. All you have to do is invoke the wrath of undefined
    behavior, often by loading up a pointer with something illegal, and
    then using it.
     
    Gordon Burditt, Feb 28, 2008
    #11
  12. satheesh

    Guest

    On Feb 28, 9:22 am, (Gordon Burditt) wrote:
    > >clanguagecan protect the data in scopes private,protected and
    > >public(may be) in structure and union?

    >
    > No.  There are no scopes private, protected and public inC.
    >
    > You are looking for C++.  And C++ cannot really protect (as in
    > prevent access) either.  The protection only works if everyone obeys
    > the rules.  All you have to do is invoke the wrath of undefined
    > behavior, often by loading up a pointer with something illegal, and
    > then using it.


    In C There is no Private, Public,protected so there is no case of
    protection.
    in C++ There is Private ,Public Protected. If you follows rules it is
    protected . if you are not following you still can access Private Data
    even in C++.
     
    , Mar 12, 2008
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr, MCSD

    Re: Protect local data files from download?

    Steve C. Orr, MCSD, Jul 4, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    315
    Steve Brecher
    Jul 4, 2003
  2. Ken Cox [Microsoft MVP]

    Re: Protect local data files from download?

    Ken Cox [Microsoft MVP], Jul 5, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    351
    Ken Cox [Microsoft MVP]
    Jul 5, 2003
  3. Chris Fogelklou
    Replies:
    36
    Views:
    1,391
    Chris Fogelklou
    Apr 20, 2004
  4. piruk
    Replies:
    1
    Views:
    388
    Ian Collins
    Apr 1, 2007
  5. John Reye
    Replies:
    28
    Views:
    1,374
    Tim Rentsch
    May 8, 2012
Loading...

Share This Page