![]() |
c can protect the data in struct
c language can protect the data in scopes private,protected and
public(may be) in structure and union? |
Re: c can protect the data in struct
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? |
Re: c can protect the data in struct
On Feb 27, 6:35*pm, santosh <santosh....@gmail.com> 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. |
Re: c can protect the data in struct
On Feb 27, 8:47*am, satheesh <satheesh....@gmail.com> wrote:
> On Feb 27, 6:35*pm, santosh <santosh....@gmail.com> 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 |
Re: c can protect the data in struct
satheesh wrote:
> On Feb 27, 6:35*pm, santosh <santosh....@gmail.com> 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++ |
Re: c can protect the data in struct
i studied in trichy LINSOFT. He teach this program.
|
Re: c can protect the data in struct
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> |
Re: c can protect the data in struct
On Wed, 27 Feb 2008 08:00:34 -0600, satheesh wrote
(in article <8b1d4b15-cdb2-45dc-8004-543a61734bb1@u10g2000prn.googlegroups.com>): > 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 |
Re: c can protect the data in struct
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 esosman@ieee-dot-org.invalid |
Re: c can protect the data in struct
satheesh <satheesh.web@gmail.com> writes:
> On Feb 27, 6:35Â*pm, santosh <santosh....@gmail.com> 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) <kst-u@mib.org> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister" |
| All times are GMT. The time now is 01:58 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.