c can protect the data in struct

S

satheesh

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

santosh

satheesh said:
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?
 
S

satheesh

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.
 
S

suresh shenoy

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
 
S

santosh

satheesh said:
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++
 
R

Randy Howard

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.
 
E

Eric Sosman

satheesh said:
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?
 
K

Keith Thompson

satheesh said:
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.
 
G

Gordon Burditt

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.
 
Y

yad.naveen

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++.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top