473,499 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why this is wrong?

Hi,
I have this code,

unsigned int input_0[8];

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;

The compiler is gcc ported to a specific embedded processor. The
compiler complains that I can not use increment operation like that.

Do you know why?

Jun 14 '06 #1
11 1592
On 13 Jun 2006 17:13:46 -0700
li*****@hotmail.com wrote:
Hi,
I have this code,

unsigned int input_0[8];

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;

The compiler is gcc ported to a specific embedded processor. The
compiler complains that I can not use increment operation like that.

Do you know why?


Because the C standard doesn't say it should be allowed.
Jun 14 '06 #2
In article <11**********************@f14g2000cwb.googlegroups .com>,
<li*****@hotmail.com> wrote:
unsigned int input_0[8];

*input_0++ = 100;


input_0 is an array. You can't increment it.

But you can set a pointer to the start of the array and then increment
that:

unsigned int *p = &input_0[0]; /* or just p = input */
*p++ = 100;
...

-- Richard
Jun 14 '06 #3
On 13 Jun 2006 17:13:46 -0700, li*****@hotmail.com wrote in
comp.lang.c:
Hi,
I have this code,

unsigned int input_0[8];

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;

The compiler is gcc ported to a specific embedded processor. The
compiler complains that I can not use increment operation like that.

Do you know why?


Because input_0 is an array, not a pointer, and you cannot increment
an array.

An array is not a pointer, and a pointer is not an array. Far too
many newbies (and some oldbies) never grasp this.

--
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
Jun 14 '06 #4
On Wed, 14 Jun 2006 01:34:03 -0500, Jack Klein <ja*******@spamcop.net>
wrote:
On 13 Jun 2006 17:13:46 -0700, li*****@hotmail.com wrote in
comp.lang.c:
Hi,
I have this code,

unsigned int input_0[8];

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;

The compiler is gcc ported to a specific embedded processor. The
compiler complains that I can not use increment operation like that.

Do you know why?


Because input_0 is an array, not a pointer, and you cannot increment
an array.

An array is not a pointer, and a pointer is not an array. Far too
many newbies (and some oldbies) never grasp this.


As demonstrated by the following code:

void print_array_size(const int array[])
{
printf("array size = %lu\n", (unsigned long)(sizeof array));
}

int main(void)
{
int array[16] = {0};
print_array_size(array);
return 0;
}

--
jay
Jun 14 '06 #5
li*****@hotmail.com wrote:
Hi,
I have this code,

unsigned int input_0[8];

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;

The compiler is gcc ported to a specific embedded processor. The
compiler complains that I can not use increment operation like that.

Do you know why?


Yes.

You can't increment an array. Why did you think you could?

--
Chris "seeker" Dollin
"We did not have time to find out everything we wanted to know." /A Clash of Cymbals/

Jun 14 '06 #6
jaysome <ja*****@spamcop.net> writes:
On Wed, 14 Jun 2006 01:34:03 -0500, Jack Klein <ja*******@spamcop.net>
wrote:

[...]
An array is not a pointer, and a pointer is not an array. Far too
many newbies (and some oldbies) never grasp this.


As demonstrated by the following code:

void print_array_size(const int array[])
{
printf("array size = %lu\n", (unsigned long)(sizeof array));
}

int main(void)
{
int array[16] = {0};
print_array_size(array);
return 0;
}


The object "array" in main() is an array.

The object (parameter) "array" in print_array_size() is a pointer, not
an array. The rule that a parameter declaration such as "int foo[]"
is quietly transformed to the equivalent of "int *foo*" is, in my
humble opinion, unfortunate.

--
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.
Jun 14 '06 #7
On Wed, 14 Jun 2006 08:37:37 GMT, Keith Thompson <ks***@mib.org>
wrote:
jaysome <ja*****@spamcop.net> writes:
On Wed, 14 Jun 2006 01:34:03 -0500, Jack Klein <ja*******@spamcop.net>
wrote:

[...]
An array is not a pointer, and a pointer is not an array. Far too
many newbies (and some oldbies) never grasp this.


As demonstrated by the following code:

void print_array_size(const int array[])
{
printf("array size = %lu\n", (unsigned long)(sizeof array));
}

int main(void)
{
int array[16] = {0};
print_array_size(array);
return 0;
}


The object "array" in main() is an array.

The object (parameter) "array" in print_array_size() is a pointer, not
an array. The rule that a parameter declaration such as "int foo[]"
is quietly transformed to the equivalent of "int *foo*" is, in my
humble opinion, unfortunate.


Yes. Languages such as C and C++ suffer from this, while languages
such as Ada and C# are more fortunate.

--
jay
Jun 14 '06 #8
unsigned int input_0[8];
unsigned int *p_inp = input_0;

*p_inp_0++ = 100;

..............................
li*****@hotmail.com wrote:
Hi,
I have this code,

unsigned int input_0[8];

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;

The compiler is gcc ported to a specific embedded processor. The
compiler complains that I can not use increment operation like that.

Do you know why?


Jun 14 '06 #9
li*****@hotmail.com wrote:

Hi,
I have this code,

unsigned int input_0[8];

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;

The compiler is gcc ported to a specific embedded processor. The
compiler complains that I can not use increment operation like that.

Do you know why?

Your variable "input_0" is an array name, and thus a constant.
It can *not* be incremented. Try this:

unsigned int *uiray[8];
unsigned int *input_0 = uiray;

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;
In this code, "input_0" is a pointer, *not* an array name.

--
+----------------------------------------------------------------+
| Charles and Francis Richmond richmond at plano dot net |
+----------------------------------------------------------------+
Jun 14 '06 #10
Charles Richmond wrote:
li*****@hotmail.com wrote:
Hi,
I have this code,

unsigned int input_0[8];

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;

The compiler is gcc ported to a specific embedded processor. The
compiler complains that I can not use increment operation like that.

Do you know why?

Your variable "input_0" is an array name, and thus a constant.
It can *not* be incremented. Try this:

unsigned int *uiray[8];
unsigned int *input_0 = uiray;

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;
In this code, "input_0" is a pointer, *not* an array name.

--
+----------------------------------------------------------------+
| Charles and Francis Richmond richmond at plano dot net |
+----------------------------------------------------------------+


why not just do:

int a = 0;
unsigned int input_0[8];

input_0[a++] = 100;
input_0[a++] = 200;
input_0[a++] = 300;
input_0[a++] = 400;
input_0[a++] = 1;
input_0[a++] = 2;
input_0[a++] = 3;
input_0[a] = 4;

or hell, just:

unsigned int input_0[8];

input_0[0] = 100;
etc.
Jun 14 '06 #11
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Scott W wrote:
Charles Richmond wrote:
li*****@hotmail.com wrote:
Hi,
I have this code,

unsigned int input_0[8];

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;

The compiler is gcc ported to a specific embedded processor. The
compiler complains that I can not use increment operation like that.

Do you know why?

Your variable "input_0" is an array name, and thus a constant.
It can *not* be incremented. Try this:

unsigned int *uiray[8];
unsigned int *input_0 = uiray;

*input_0++ = 100;
*input_0++ = 200;
*input_0++ = 300;
*input_0++ = 400;
*input_0++ = 1;
*input_0++ = 2;
*input_0++ = 3;
*input_0 = 4;
In this code, "input_0" is a pointer, *not* an array name.

--
+----------------------------------------------------------------+
| Charles and Francis Richmond richmond at plano dot net |
+----------------------------------------------------------------+


why not just do:

int a = 0;
unsigned int input_0[8];

input_0[a++] = 100;
input_0[a++] = 200;
input_0[a++] = 300;
input_0[a++] = 400;
input_0[a++] = 1;
input_0[a++] = 2;
input_0[a++] = 3;
input_0[a] = 4;

or hell, just:

unsigned int input_0[8];

input_0[0] = 100;
etc.


or even

int a = 7;
unsigned int input_0[8] = { 100, 200, 300, 400, 1, 2, 3, 4};

which would produce the same end state

- --

Lew Pitcher, IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEkEM8agVFX4UWr64RAjalAJ9T8HTTtL/H7c5icZ0EU1OKsCKhlwCfZ7yy
0aGWb5Q7RDlJYOg6b27mTew=
=LsN2
-----END PGP SIGNATURE-----
Jun 14 '06 #12

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

Similar topics

21
3868
by: Jay Levitt | last post by:
I'm just starting to play around with CSS and MovableType. My home page (http://www.jay.fm) now validates on both the CSS and the XHTML. However, the Google cached version shows the wrong font in...
7
5684
by: Jerry Krinock | last post by:
I've declared a class that has some std::vector data members like this: class MyClass { public: ... std::vector<Apples> apples ; ... private: ...
5
2816
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
5
2696
by: Krisnamourt Correia via SQLMonster.com | last post by:
I have one query that executes many times in a week. I created one Maintenances plan that Rebuild all index in my Database that has been executed at 23:40 Saturday until stop finished at Sunday. ...
6
6553
by: Michael Sparks | last post by:
Hi, I suspect this is a bug with AMK's Crypto package from http://www.amk.ca/python/code/crypto , but want to check to see if I'm being dumb before posting a bug report. I'm looking at...
3
5467
by: Soren Jorgensen | last post by:
Hi, Following code should give the number of weeks in years 1998-2010 for a Danish calendar (on a Danish box) GregorianCalendar cal = new GregorianCalendar(); for(int i = 1998; i < 2010; i++)...
8
2002
by: Dmitry Korolyov | last post by:
ASP.NET app using c# and framework version 1.1.4322.573 on a IIS 6.0 web server. A single-line asp:textbox control and regexp validator attached to it. ^\d+$ expression does match an empty...
3
2728
by: belton180 | last post by:
CODE]../* Program function: Simulate the stack using a stack limit of 10. Display a menu for the the following. Create a stack Insert an item in the stack Pop an item from the stack ...
318
12706
by: jacob navia | last post by:
Rcently I posted code in this group, to help a user that asked to know how he could find out the size of a block allocated with malloc. As always when I post something, the same group of people...
3
2131
by: Siong.Ong | last post by:
Dear all, my PHP aims to update a MySQL database by selecting record one by one and modify then save. Here are my PHP, but I found that it doesnt work as it supposed to be, for example, when...
0
7174
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,...
0
7220
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...
0
7388
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
4600
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...
0
3099
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
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
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.