473,503 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Implementing

Hi all !!
I need to know that in C how to implement sizeof() without using the
keyword?
The implementation should be generic.
e.g
malloc(sizeof(struct));

Here the sizeof() returns the number of bytes reserved and is a
reserved keyword which calls a function through the library function.
But i want to implement the working of sizeof() without using the
keyword.
Hope all of ya got my Question.
Hoping to read from all of you soon
Thnx in advance.

Jan 29 '06 #1
6 1529
cogno_byte wrote:
I need to know that in C how to implement sizeof() without using the
keyword?
Your sentence makes no sense. Please use proper English.

sizeof is an operator, not a function, in C. For all objects except
variable length arrays the compiler knows from the declaration how large
the object or type is and gives that value as the result of the
operator. The way it is implemented is part of the compilation process,
with access to the symbol table, not a runtime operation. VLAs are
handled somewhat differently, since their size is not constant.
The implementation should be generic.
e.g
malloc(sizeof(struct));

Here the sizeof() returns the number of bytes reserved and is a
reserved keyword which calls a function through the library function.
But i want to implement the working of sizeof() without using the
keyword.


You could design your own language with your own keywords and implement
a compiler for it.

--
Thad
Jan 29 '06 #2
"cogno_byte" <b.************@gmail.com> writes:
I need to know that in C how to implement sizeof() without using the
keyword?


Why do you want to do this? It's like asking how to drive a nail
without using a hammer.

Just use sizeof().

If you really do have a reason to want to do this, it's been asked
before. Check the archives.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 29 '06 #3
Keith Thompson said:
Just use sizeof().


Better still, use sizeof - which does not require its operand to be
parenthesised (unless it's a type name).
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jan 29 '06 #4
cogno_byte said:
Here the sizeof() returns the number of bytes reserved
No, it doesn't.

"The sizeof operator yields the size (in bytes) of its operand, which may be
an expression or the parenthesized name of a type. The size is determined
from the type of the operand, which is not itself evaluated. The result is
an integer constant." - C89 3.3.3.4
and is a
reserved keyword which calls a function through the library function.


Chapter and verse, please. I know of no requirement for sizeof to call a
function.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jan 29 '06 #5
cogno_byte wrote:

I need to know that in C how to implement sizeof() without using
the keyword?
The implementation should be generic.
e.g
malloc(sizeof(struct));

Here the sizeof() returns the number of bytes reserved and is a
reserved keyword which calls a function through the library function.
But i want to implement the working of sizeof() without using the
keyword.


Can't be done. That is why it is supplied by the system, whose
designer is allowed to use non-portable things to implement it.

--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943
Jan 29 '06 #6
On 28 Jan 2006 22:35:43 -0800, "cogno_byte" <b.************@gmail.com>
wrote in comp.lang.c:
Hi all !!
I need to know that in C how to implement sizeof() without using the
keyword?


Use COBOL.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jan 29 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
14886
by: MKoleoso | last post by:
Problem: C#- Unable to create instance of a class implementing from an interface I have: namespace someNamespace { public __gc class SomeClass1 { }
1
6463
by: Maurice | last post by:
Hi, We are implementing some wrappers in C++ according to the Adapter Pattern. The classes and their methods in the Adaptee classes (open-source library) have already the interface that we like,...
4
2049
by: Frank J. Reashore | last post by:
Hello Everyone, I am implementing a simple interface in C# using Visual Studio .net and was quite surprised to discover that the C# compiler does NOT complain if a method on the interface is not...
7
2084
by: Scott M. | last post by:
In a typical class, do I need to indicate that it implements the IDisposable interface and then create a Dispose method that implements the Dispose required by the IDisposable interface or can I...
4
3304
by: phl | last post by:
hi, My question is: 1. To avoid possible memory leaks, when you use this pattern, after you have dealth with the unmanaged resources and before you take your object off the finalize queue,...
6
8496
by: Raj Wall | last post by:
Hi, I am trying to implement the IEqualityComparer interface for a struct so I can use it as the Key for a Dictionary. My struct declaration has: public struct Ring : IEqualityComparer {...
5
3530
by: koonda | last post by:
Hi all, I am a student and I have a project due 20th of this month, I mean May 20, 2007 after 8 days. The project is about creating a Connect Four Game. I have found some code examples on the...
2
1980
by: Ian Semmel | last post by:
I am new to this world of ASP.NET so forgive the dumb questions. I have been looking at the sample provided 'Implementing a Session-State Store Provider' in an effort to understand how the...
4
2102
by: Mohamed Mansour | last post by:
Hello, What is the purpose of implementing the Observer Pattern if we can trigger an event easily? For example (from books), You have a "Forecaster" which notifies "Observable" when a...
1
1769
by: aditi kauts | last post by:
Hi I am implementing security on Contact base smart card which follows scosta template. In card structure ef is directly under DF and DF is directly under MF. According to the template i am...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
382
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.