From: Vadiraj C S <vadiraj@mail.cyberneme.com>
To: "John T. Williams" <jtwilliams@vt.edu>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: literal constant..
Date: Tue, 3 Feb 2004 13:04:07 +0530 [thread overview]
Message-ID: <20040203130407.1f77d692.vadiraj@mail.cyberneme.com> (raw)
In-Reply-To: <006601c3ea24$c694d230$ed64a8c0@descartes>
On Tue, 3 Feb 2004 02:10:16 -0500
"John T. Williams" <jowillia@vt.edu> wrote:
> char *a = "a";
> means create a pointer and point it at a point in memory that contains the
> string "a"
>
> char b[1] = "b";
> means create a constant pointer and non-dynamic memory of size 1 char ( 1
> byte ), point the pointer to the memory and assign it the value of "b"
>
> the major difference is that in the case of 'b', 'b' is a constant pointer
> to a specific place in memory on the stack. while 'a' can point to any
> legal memory address.
>
Ok this is the asm code for the array decl case c[1]="1".....
.file "temp.c"
.section .rodata
.LC0:
.string "1"
.text
.align 2
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movb .LC0, %al
movb %al, -1(%ebp)
movb $50, -1(%ebp)
leave
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 3.2"
----------------------------
This is for the pointer dicleration *c = "1"
I do
.file "temp.c"
.section .rodata
.LC0:
.string "1"
.text
.align 2
.globl main
.type main,@function
main:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
movl $0, %eax
subl %eax, %esp
movl $.LC0, -4(%ebp)
movl -4(%ebp), %eax
movb $50, (%eax)
leave
ret
.Lfe1:
.size main,.Lfe1-main
.ident "GCC: (GNU) 3.2"
I do c[0]="2" in both the case, the pointer case it fails cos the values should be constant.
the diff is only two line
< movb .LC0, %al
< movb %al, -1(%ebp)
< movb $50, -1(%ebp)
---
> movl $.LC0, -4(%ebp)
> movl -4(%ebp), %eax
> movb $50, (%eax)
I clould not get much about it, Please help me in this...
Thanks
next prev parent reply other threads:[~2004-02-03 7:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-03 6:46 literal constant Vadiraj C S
[not found] ` <006601c3ea24$c694d230$ed64a8c0@descartes>
2004-02-03 7:34 ` Vadiraj C S [this message]
2004-02-03 15:07 ` Glynn Clements
-- strict thread matches above, loose matches on Subject: below --
2004-02-03 11:41 Sandro Dangui
2004-02-03 14:34 ` Florian Attenberger
2004-02-03 15:04 ` John T. Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040203130407.1f77d692.vadiraj@mail.cyberneme.com \
--to=vadiraj@mail.cyberneme.com \
--cc=jtwilliams@vt.edu \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).