473,657 Members | 2,428 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(s truct));

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 1536
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(s truct));

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_Keit h) 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(s truct));

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.l earn.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
14930
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
6469
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, but we want to rename them so we want to implement the Adapter classes in such a way that we only have to rename the Adaptee classes. We prefer to use #define's because of the better run-time performance, in stead of implementing wrapper...
4
2058
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 implemented. VB.net on the other hand generates a compile error if a method is not implemented. This helps in ensuring that all interface methods are implemented.
7
2089
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 just make a Sub Dispose() and the CLR will know that this is the Dispose method to call when the object falls out of scope? Thanks.
4
3323
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, how are you sure that your managed object resources are completely freed up of resources it's might be using? In my case below I have a private bool variable. Are there any other managed resource that you might need to explicitly free up in
6
8504
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 { .... } and I am trying to implement the Equals and GetHashCode methods.
5
3539
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 internet which helped me little bit. But there are lot of problems I am facing developing the whole game. I have drawn the Board and the two players can play. The players numbers can fill the board, but I have problem implementing the winner for the...
2
1984
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 thing works. Now, my question is, if I have this code, what do I do with it. Where do
4
2109
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 prediction is ready, then there is a "WeatherViewer" which calls methods from the "Observer Interface".
1
1776
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 implementing security on elementary file(both sac and sae attributes are specified at time of creation in fcp) according to security condition read and update of record requires verification of pin(which is already defined in pin file). Problem is that...
0
8420
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.