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? 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.
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
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
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 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/
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.
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
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? 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 |
+----------------------------------------------------------------+
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.
-----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----- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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:
...
|
by: titan0111 |
last post by:
#include<iostream>
#include<iomanip>
#include<cstring>
#include<fstream>
using namespace std;
class snowfall
{
private:
int ft;
|
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.
...
|
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...
| |
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++)...
|
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...
|
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
...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |