Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > [C] Pointer to ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 24 Topic 4140 of 4295
Post > Topic >>

[C] Pointer to an array

by Aggro <spammerdream@[EMAIL PROTECTED] > May 14, 2008 at 03:14 PM

--------------- output from my console ------------
$ cat code1.c
#include <string.h>
int main()
{
   char usr_data[128];
   memset( &usr_data, 0, 128 );
   return 0;
}

$ gcc code1.c
$ md5sum a.out
653c4838fdbbdde05c832f79765fa143  a.out
$ nano code1.c
$ cat code1.c
#include <string.h>
int main()
{
   char usr_data[128];
   memset( usr_data, 0, 128 );
   return 0;
}

$ gcc code1.c
$ md5sum a.out
653c4838fdbbdde05c832f79765fa143  a.out
--------------- output from my console ------------

There a few things I would like you to note.
1. The parameter for the memset is first "&usr_data", then it is
"usr_data"
2. The md5sum for the generated binary file is identical. Also the 
behaviour as far as I could tell is identical. Also sha1sum is 
identical. So it looks like the binary files are identical.

Question: How is it possible that the binary files are identical with 
these two different source codes?

And how is it possible that both applications fill the usr_data with 
zeroes? Shouldn't the first example just cause somekind of error? I 
would understand if the behaviour in that case would be undefined and is 
just happens to work correctly, but because the binary files are 
identical, it doesn't make sence.


TIA
 




 24 Posts in Topic:
[C] Pointer to an array
Aggro <spammerdream@[E  2008-05-14 15:14:02 
Re: [C] Pointer to an array
Richard Heathfield <rj  2008-05-14 16:30:48 
Re: [C] Pointer to an array
Ben Bacarisse <ben.use  2008-05-14 17:44:04 
Re: [C] Pointer to an array
Aggro <spammerdream@[E  2008-05-14 18:15:40 
Re: [C] Pointer to an array
Richard Heathfield <rj  2008-05-14 18:32:05 
Re: [C] Pointer to an array
Aggro <spammerdream@[E  2008-05-14 18:36:49 
Re: [C] Pointer to an array
Richard Heathfield <rj  2008-05-14 18:55:56 
Re: [C] Pointer to an array
Keith Thompson <kst-u@  2008-05-14 13:10:50 
Re: [C] Pointer to an array
Andrey Tarasevich <and  2008-05-14 11:41:42 
Re: [C] Pointer to an array
Anand Hariharan <znvyg  2008-05-21 04:44:12 
Re: [C] Pointer to an array
"Alf P. Steinbach&qu  2008-05-21 06:38:33 
Re: [C] Pointer to an array
Richard Heathfield <rj  2008-05-21 06:14:08 
Re: [C] Pointer to an array
Barry Schwarz <schwarz  2008-05-25 10:44:26 
Re: Pointer to an array
Anand Hariharan <mailt  2008-05-21 07:50:59 
Re: Pointer to an array
"Alf P. Steinbach&qu  2008-05-21 17:11:16 
Re: Pointer to an array
Bart van Ingen Schenau &l  2008-05-21 19:39:27 
Re: Pointer to an array
Andrey Tarasevich <and  2008-05-21 11:50:21 
Re: Pointer to an array
Anand Hariharan <mailt  2008-05-22 13:51:12 
Re: [C] Pointer to an array
Ben Bacarisse <ben.use  2008-05-26 16:57:06 
Re: [C] Pointer to an array
Francis Glassborow <fr  2008-05-26 19:39:07 
Re: [C] Pointer to an array
Keith Thompson <kst-u@  2008-05-26 14:14:19 
Re: [C] Pointer to an array
Ben Bacarisse <ben.use  2008-05-27 04:01:45 
Re: [C] Pointer to an array
Ben Bacarisse <ben.use  2008-05-27 04:23:15 
Re: [C] Pointer to an array
Andrey Tarasevich <and  2008-05-14 11:32:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 16:15:11 CDT 2008.