473,836 Members | 1,310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

main function address

hi,
Is main function address is 657.
its show in all compiler.
try it & say why?
bye,
Nov 14 '05
89 6544
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Keith Thompson <ks***@mib.or g> wrote:

[...]
You can interpret it as an array of unsigned char and print the values
(in, say, hexadecimal).


Myes, you can; but where pointers are sufficiently unusual for the above
not to work, is that likely to give usefully interpretable values? Maybe
so.


Maybe yes, maybe no. The hexadecimal string you get by interpreting a
function pointer as an array of unsigned bytes isn't going have any
useful portable interpretation, but it might be useful in the context
of platform-specific knowledge about the underlying representation.

There's little or no *portable* use for examining the bytes that make
up a function pointer, but it might be useful for diagnosing bizarre
problems (e.g., within a debugger).

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #81
CBFalconer wrote:

Barry Schwarz wrote:
CBFalconer <cb********@yah oo.com> wrote:
Leor Zolman wrote:

... snip ...

And therein lies my question. If pf has type pointer-to-foo, but
is printed using a %p format conversion, that represents a foo*
-> void* conversion without the compiler's "knowledge" ... when
the internals of printf extract that argument, it will at some
point be "converted" into a void *, but without any knowledge of
what it was "before". So is such an implicit conversion
officially permitted? I've been writing code that does that
forever, and it makes me wonder...

It is not permitted. The printf has no knowledge of what is
passed as parameters, other than what it is told in the format
string. So there can be no implicit conversions there. Thus it
is imperative to pass things that agree with the format string,
and therefore you must cast the pointer to a void* at function
call time.

The normal integer promotions are another matter, and occur for
all parameters passed to any functions. They can NEVER lose
information, and serve to keep the stack (assuming there is a
stack) properly aligned, among other things. Thus you cannot pass
a char, it is always promoted to int. You can, however, tell
printf how to interpret that int. Similarly you can't pass a
short, or a float, without promotions.


Are you saying that calling a von-variadic function with a proper
prototype in scope will still have char, short, and float promoted?


As usual, it depends.


The answer to the question, is "No".

N869
6.5.2.2 Function calls
[#7] If the expression that denotes the called function has
a type that does include a prototype, the arguments are
implicitly converted, as if by assignment, to the types of
the corresponding parameters, taking the type of each
parameter to be the unqualified version of its declared
type.

[#8] No other conversions are performed implicitly;

--
pete
Nov 14 '05 #82
pete wrote:

CBFalconer wrote:

Barry Schwarz wrote:
Are you saying that calling a von-variadic function with a proper
prototype in scope will still have char, short, and float
promoted?
As usual, it depends.


The answer to the question, is "No".

[#8] No other conversions are performed implicitly;


After rethinking the "implicitly " qualifier,
I think The answer might be "it depends".

--
pete
Nov 14 '05 #83
pete wrote:
pete wrote:
CBFalconer wrote:
Barry Schwarz wrote:
Are you saying that calling a von-variadic function with a proper
prototype in scope will still have char, short, and float
promoted?

As usual, it depends.


The answer to the question, is "No".


[#8] No other conversions are performed implicitly;

After rethinking the "implicitly " qualifier,
I think The answer might be "it depends".

Don't go soft on us pete. You were right the first time (I think). The
implicit conversions are done according to the language rules.

The only explicit conversions are casts.

--
Joe Wright mailto:jo****** **@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #84
"Dan Pop" <Da*****@cern.c h> wrote in message
news:c5******** ***@sunnews.cer n.ch...
In <c0************ *************** *****@4ax.com> Leor Zolman <le**@bdsoft.co m> writes:
Compared to what the committee members had to pay in order to cover their
own expenses just to be on the Standard committee, we're getting a bargain;-)


In your opinion, how many of them had to pay it from their own pocket? ;-)


Does it matter? How many of you have paid the $18 from your own pocket?

Peter
Nov 14 '05 #85
"Leor Zolman" <le**@bdsoft.co m> wrote in message
news:5t******** *************** *********@4ax.c om...
On Wed, 7 Apr 2004 18:11:06 -0400 (EDT), "Arthur J. O'Dwyer"
<aj*@nospam.and rew.cmu.edu> wrote:

On Wed, 7 Apr 2004, Leor Zolman wrote:

Arthur O'Dwyer <aj*@nospam.and rew.cmu.edu> wrote:
> Variadic functions are by definition not prototyped as expecting
> anything in particular in the "..." part. So when you have
>
> printf("foo", pf);
>
> the value of 'pf' is passed to 'printf' as a pointer to foo, no
> matter what the function actually expects.

And therein lies my question. If pf has type pointer-to-foo, but is printed using a %p format conversion, that represents a foo* -> void* conversion without the compiler's "knowledge" ... when the internals of printf extract that argument, it will at some point be "converted" into a void *, but
without any knowledge of what it was "before". So is such an implicit
conversion officially permitted? I've been writing code that does that
forever, and it makes me wonder...


If you pass a value of type T to a variadic function, and that function
is expecting a value of type U instead, then you have undefined behavior,
unless <some legalese involving cv-qualification>. It's not terribly
unintuitive, is it?


Actually, it /is/ rather unintuitive to me that in the modern world of the
flat memory model, you can't just pass a foo * in order to print its value
(and be blessed by the Standard) without first casting it to void *.
That's why I wanted to make sure. But if that's the way it is, that's the
way it is. Just one more item for my posting checklist.


The C Standard does not require a flat memory model, and C is implemented on
many systems which don't use one. While the behavior of passing an
incorrectly typed pointer works on flat memory systems, it can't be blessed
by the Standard while retaining support for non-flat systems.

S

--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin
Nov 14 '05 #86
Stephen Sprunk wrote:
The C Standard does not require a flat memory model
and C is implemented on many systems which don't use one.
Can you name one such system
which supports and ANSI/ISO C 99 compliant implementation?
While the behavior of passing an incorrectly typed pointer
works on flat memory systems,
it can't be blessed by the Standard
while retaining support for non-flat systems.


The ANSI/ISO C [89]9 standards don't specify a "flat memory model"
because they don't need to. You can assume a flat memory model
and your code will port almost everywhere.
The exceptions, if there are any, are almost never targets
for most application programs anyway.

My advice is this,
"Unless you can identify a target for your application
which does not support `a flat memory model',
it isn't worth your time to worry about it."

Nov 14 '05 #87
In <40***********@ mindspring.com> pete <pf*****@mindsp ring.com> writes:
pete wrote:

CBFalconer wrote:
>
> Barry Schwarz wrote: > > Are you saying that calling a von-variadic function with a proper
> > prototype in scope will still have char, short, and float
> > promoted?
>
> As usual, it depends.


The answer to the question, is "No".

[#8] No other conversions are performed implicitly;


After rethinking the "implicitly " qualifier,
I think The answer might be "it depends".


You actually have to rethink the as-if rule. The compiler can perform
any conversions it wants, as long as no correct program can tell the
difference. Imagine an implementation handling the following code

void display(char c)
{
putchar(c);
}

int main()
{
char c = 'a';
display(c);
...
}

by converting char arguments to int and having the functions defined with
char parameters by expecting them to be passed as int's. If such
functions only use the LSB of their char parameters, no correct program
will be able to tell the difference. And this scenario is quite
popular on implementations passing the arguments in registers.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #88
Da*****@cern.ch (Dan Pop) writes:
In <40***********@ mindspring.com> pete <pf*****@mindsp ring.com> writes:
pete wrote:
CBFalconer wrote:
> Barry Schwarz wrote:
> > Are you saying that calling a von-variadic function with a proper
> > prototype in scope will still have char, short, and float
> > promoted?
>
> As usual, it depends.

The answer to the question, is "No".

[#8] No other conversions are performed implicitly;


After rethinking the "implicitly " qualifier,
I think The answer might be "it depends".


You actually have to rethink the as-if rule. The compiler can perform
any conversions it wants, as long as no correct program can tell the
difference.

void display(char c)
{
putchar(c);
}

int main()
{
char c = 'a';
display(c);
...
}

by converting char arguments to int and having the functions defined with
char parameters by expecting them to be passed as int's. If such
functions only use the LSB of their char parameters, no correct program
will be able to tell the difference. And this scenario is quite
popular on implementations passing the arguments in registers.


Hmm. I wouldn't actually describe that as a "conversion "; rather, I'd
say that the argument-passing convention for type char passes
int-sized chunks of data.

But both descriptions are probably equally valid.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #89
In <ln************ @nuthaus.mib.or g> Keith Thompson <ks***@mib.or g> writes:
Da*****@cern.c h (Dan Pop) writes:
In <40***********@ mindspring.com> pete <pf*****@mindsp ring.com> writes:
>pete wrote:
>> CBFalconer wrote:
>> > Barry Schwarz wrote:
>> > > Are you saying that calling a von-variadic function with a proper
>> > > prototype in scope will still have char, short, and float
>> > > promoted?
>> >
>> > As usual, it depends.
>>
>> The answer to the question, is "No".
>
>> [#8] No other conversions are performed implicitly;
>
>After rethinking the "implicitly " qualifier,
>I think The answer might be "it depends".


You actually have to rethink the as-if rule. The compiler can perform
any conversions it wants, as long as no correct program can tell the
difference.

void display(char c)
{
putchar(c);
}

int main()
{
char c = 'a';
display(c);
...
}

by converting char arguments to int and having the functions defined with
char parameters by expecting them to be passed as int's. If such
functions only use the LSB of their char parameters, no correct program
will be able to tell the difference. And this scenario is quite
popular on implementations passing the arguments in registers.


Hmm. I wouldn't actually describe that as a "conversion "; rather, I'd
say that the argument-passing convention for type char passes
int-sized chunks of data.


It's more than that: the char value is sign-extended, so the upper bytes
don't contain junk. This is useful for code optimisations: the parameter
may end up spending its entire life in a register.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #90

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

Similar topics

11
6922
by: Sweety | last post by:
hello to all members, i have strange question in C. main() { printf("%d",main) ; } here o/p is same for all m/c in TC++ version 3.0 i.e 657. I think this is not garbage.
75
596
by: Sweety | last post by:
hi, Is main function address is 657. its show in all compiler. try it & say why? bye,
9
3725
by: DanielJohnson | last post by:
I am wondering where does the value returned by main goes. Suppoes main returns some number say 42, where is it stored. Supposed a shell script call a C program and the program returns the value 42 where is this value stored in memory ?
1
1802
by: davidcollins001 | last post by:
Hi, I am trying to write a stack walking program to trace back along the stack for a process that the trace function is called from. I am doing it the cheating way, in that I have a ruby program (not mine) that fills in an array with the names of functions and arguments, arg types and arguments offset from that frames ebp for all of the functions on the stack. So far I have been able to get it working correctly for all functions except for...
0
9813
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
9665
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
10835
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...
0
10541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10249
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
9367
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
6976
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();...
0
5645
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4007
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.