473,805 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

int a[17]; int b = -1; /* a[17] same as b guaranteed in ANSI C? */

bq
In the code
int a[17];
int b = -1;
does ANSI C guarantee that "b" is located in memory right after "a[16]"
so that "a[17]" refers to "b"?

Thanks.
bq
Nov 14 '05
44 1978

"Joona I Palaste" <pa*****@cc.hel sinki.fi> wrote in message
news:br******** **@oravannahka. helsinki.fi...
Christopher Benson-Manica <at***@nospam.c yberspace.org> scribbled the

following:
Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus:
until I got fired)

*You* got fired? How'd you manage that?

(the point being that, if you, being much more competent than I, are
being fired, I may have some issues in my future...)


I got fired because the company had to subsidise (sp?) to avoid going
bankrupt, and I was chosen as "least productive programmer". Not "least
competent" - least *productive*. The code I was writing was fine, but it
could just as well have been written by any other programmer on our
team.


SW business is cruel. I just read about the book
Everyone Else Must Fail: The Unvarnished Truth About Oracle and Larry
Ellison
from Slashdot. Name of the book is quote from Genghis Khan "It is not
sufficient that I succeed. Everyone else must fail." which Larry uses quite
often!

SW business is cruel and so are comp.lang.c moderators who are just now
planning to ban us for off-topic issues ;-)

with respect,
Toni Uusitalo Everyone Else Must Fail: The Unvarnished Truth About Oracle
and Larry Ellison
Everyone Else Must Fail: The Unvarnished Truth About Oracle and Larry
Ellison
Nov 14 '05 #31
Kevin Goodsell wrote:

Joona I Palaste wrote:
Christopher Benson-Manica <at***@nospam.c yberspace.org> scribbled the following:
Joona I Palaste <pa*****@cc.hel sinki.fi> spoke thus:

until I got fired)
*You* got fired? How'd you manage that?


(the point being that, if you, being much more competent than I, are
being fired, I may have some issues in my future...)

I got fired because the company had to subsidise (sp?) to avoid going
bankrupt, and I was chosen as "least productive programmer". Not "least
competent" - least *productive*. The code I was writing was fine, but it
could just as well have been written by any other programmer on our
team.


Man, that sucks. :(

I don't suppose they took into consideration anything other than amount
of code? So you might have been producing code that took a little longer
to write, but which saved a great deal of time in debugging and
maintenance, and was of overall better quality. But the managers
apparently aren't getting paid to look at the big picture, so you get
the boot.

I'm guessing they let go of one of their best programmers. Those kinds
of decisions are probably a major reason for their financial troubles.


It depends heavily on the problem domain, but financial sensitivity to
programmer productivity is not a clearly shown thing.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

--
Les Cargill
Nov 14 '05 #32
Toni Uusitalo <to************ **@luukkudot.ko m> wrote:
SW business is cruel and so are comp.lang.c moderators who are just now
planning to ban us for off-topic issues ;-)


We don't have moderators. If you want to be silenced, try
comp.lang.c.mod erated.

Alex
Nov 14 '05 #33

"Alex" <al*******@hotm ail.com> wrote in message
news:br******** ****@ID-190529.news.uni-berlin.de...
Toni Uusitalo <to************ **@luukkudot.ko m> wrote:
SW business is cruel and so are comp.lang.c moderators who are just now
planning to ban us for off-topic issues ;-)


We don't have moderators. If you want to be silenced, try
comp.lang.c.mod erated.


silenced? I doubt if I dare to go there. Sounds like they've got hitmen or
something...
But thanks for the warning ;-)

with respect,
Toni Uusitalo
Nov 14 '05 #34
Kevin Goodsell <us************ *********@never box.com> wrote in message news:<sW******* **********@news read2.news.pas. earthlink.net>. ..
Nudge wrote:
Christopher Benson-Manica wrote:
You didn't quote the Standard ;( I know a+17 is legal, and I also
know that *(a+17) is illegal and that a+18 is also illegal...

How can a+18 be illegal?


What would the rationale be to allow a+17 to be legal yet a+18
illegal ? Is it for running trough a series of bytes and being
able to check the pointer value for beyond the bound conditions,
so that UB accesses are not made? If so what would be a similar
method for a pointer being incremented by 2 in a loop?

<snipped>
In other words, you may form (but not dereference) a pointer to the area
one past the end of an array, but no farther. You cannot, in general,
create any pointer value you feel like. The behavior is undefined if you
create a "bad" pointer value - even if you don't dereference it.

Nov 14 '05 #35
Anupam <an************ **@persistent.c o.in> spoke thus:
What would the rationale be to allow a+17 to be legal yet a+18
illegal ? Is it for running trough a series of bytes and being
able to check the pointer value for beyond the bound conditions,
so that UB accesses are not made? If so what would be a similar
method for a pointer being incremented by 2 in a loop?


Generating a pointer to one past the end of an array is allowed to
make constructs like the following legal:

char *MyStrcpy( char * const lhs, const char * rhs) {
char *p=lhs;

if( lhs != rhs ) {
while( *p++ = *rhs++ )
;
}

return lhs;
}

(reference: Efficient C Programming, Weiss. p 198)

The loop terminates when the null terminator of rhs is reached. At
that point, rhs is incremented again to one past the end of the string
rhs points to, but the resulting pointer is never dereferenced.
Allowing generation of pointers to other out-of-bounds elements is disallowed
by the Standard because of the undue burden that would be placed on
some implementors - for much the same reason, I imagine, that only one
character of pushback with ungetc() is required.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #36
On 20 Dec 2003 11:06:48 -0800
an************* *@persistent.co .in (Anupam) wrote:
Kevin Goodsell <us************ *********@never box.com> wrote in message
news:<sW******* **********@news read2.news.pas. earthlink.net>. ..
Nudge wrote:
Christopher Benson-Manica wrote:

>You didn't quote the Standard ;( I know a+17 is legal, and I also
>know that *(a+17) is illegal and that a+18 is also illegal...
How can a+18 be illegal?

What would the rationale be to allow a+17 to be legal yet a+18
illegal ? Is it for running trough a series of bytes and being
able to check the pointer value for beyond the bound conditions,
so that UB accesses are not made?


Yes, the one past is to allow increment then test for being past the
end. It is also because it was common practise when the first C standard
was written.
If so what would be a similar
method for a pointer being incremented by 2 in a loop?


There isn't. It is up to you to ensure that the pointer goes at most one
past the end.
--
Flash Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spam, it is real and I read it.
Nov 14 '05 #37
On Thu, 18 Dec 2003 18:55:37 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.c yberspace.org> wrote:
Is (a+17)==&b a legal comparison?


No. They aren't pointers to the same object.
--
#include <standard.discl aimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
Nov 14 '05 #38
On Sat, 27 Dec 2003 15:40:10 -0800, Kevin D. Quitt
<KQ**********@I EEIncUNMUNG.com > wrote:

On Thu, 18 Dec 2003 18:55:37 +0000 (UTC), Christopher Benson-Manica
<at***@nospam. cyberspace.org> wrote:
Is (a+17)==&b a legal comparison?


No. They aren't pointers to the same object.


Apparently they don't have to be - 6.5.9:

6 Two pointers compare equal if and only if both are null pointers, both
are pointers to the same object (including a pointer to an object and a
subobject at its beginning) or function, both are pointers to one past the
last element of the same array object, or one is a pointer to one past the
end of one array object and the other is a pointer to the start of a
different array object that happens to immediately follow the first array
object in the address space.

I am surprised by that last. OTOH, 6.5.8.5:

When two pointers are compared, the result depends on the relative
locations in the address space of the objects pointed to. If two pointers
to object or incomplete types both point to the same object, or both point
one past the last element of the same array object, they compare equal. If
the objects pointed to are members of the same aggregate object, pointers
to structure members declared later compare greater than pointers to
members declared earlier in the structure, and pointers to array elements
with larger subscript values compare greater than pointers to elements of
the same array with lower subscript values. All pointers to members of the
same union object compare equal. If the expression P points to an element
of an array object and the expression Q points to the last element of the
same array object, the pointer expression Q+1 compares greater than P. In
all other cases, the behavior is undefined.
That last sentence would seem to make a comparison of a+17 and &b UB.
--
#include <standard.discl aimer>
_
Kevin D Quitt USA 91387-4454 96.37% of all statistics are made up
Per the FCA, this address may not be added to any commercial mail list
Nov 14 '05 #39
In article <l2************ *************** *****@4ax.com>,
Kevin D. Quitt <KQ**********@I EEIncUNMUNG.com > wrote:
On Thu, 18 Dec 2003 18:55:37 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.c yberspace.org> wrote:
Is (a+17)==&b a legal comparison?


No. They aren't pointers to the same object.


Yes, it is legal. They don't need to be pointers to the same object.
Nov 14 '05 #40

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

Similar topics

100
7029
by: Roose | last post by:
Just to make a tangential point here, in case anyone new to C doesn't understand what all these flame wars are about. Shorthand title: "My boss would fire me if I wrote 100% ANSI C code" We are discussing whether this newsgroup should focus on 100% ANSI C or simply topics related to the C language in the real world. There is a C standard which is defined by an international committee. People who write compilers refer to this in...
9
7066
by: Olumide | last post by:
Thats the question. I know about virtual memory, and the MMU. I just wonder if array members guaranteed to be contiguous in physical memory (and if so, why). Thanks, Olumide
127
5547
by: bz800k | last post by:
Hi Does this code satisfy ANSI C syntax ? void function(void) { int a = 2; a = ({int c; c = a + 2;}); /* <<-- here !! */ printf("a=%d\n", a);
0
10605
NeoPa
by: NeoPa | last post by:
ANSI-89 v ANSI-92 Before we get into all the various types of pattern matching that can be used, there are two ANSI standards used for the main types of wildcard matching (matching zero or more characters or simply matching a single character) : ANSI-89 - Mainly used only by Jet / ACE SQL ANSI-92 - Mainly used by SQL Server and other grown-up products In the later versions of Access it is now possible to select ANSI-92 compatibility as an...
41
3171
by: jaysome | last post by:
It's been almost eight years since ISO/IEC approved ISO/IEC 9899:1999. Does anyone know if ANSI has approved it? A Google search shows arguably confusing answers as to whether ANSI has approved it. For example, on this site: http://en.wikipedia.org/wiki/C_(programming_language)#ANSI_C_and_ISO_C it says that "It was adopted as an ANSI standard in March 2000."
2
2140
by: Mara Guida | last post by:
"Each time I run my program, I get the same sequence of numbers back from rand()." The answer to question 13.17, in the c-faq is: #include <stdlib.h> #include <time.h> srand((unsigned int)time((time_t *)NULL));
0
9596
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
10360
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...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
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
9185
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
6876
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
5542
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
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.