473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to read this function with 2 constants

if I have:

void f( const int* const p )

Do I read this as.

P is a constant pointer to an int whose value is constant?

Or, is there another interpretation?

Thanks alot for any input.
Jul 23 '05 #1
1 1357
* john smith:

NNTP-Posting-Date: Tue, 12 Apr 2005 18:53:19 MST
Date: Mon, 11 Apr 2005 20:03:55 -0700
Xref: uni-berlin.de comp.lang.c++:859528
Seems to be something wrong with your client software or server.

if I have:

void f( const int* const p )

Do I read this as.

P is a constant pointer to an int whose value is constant?
Yes.

Or, is there another interpretation?


No, but there are a few points to be aware of.

First, placing 'const' at the front is a special case that's allowed
for unfathomable reasons (making the syntax even more complex?); in
the general notation you'd write it as

int const * const p

Second, for a function _definition_ it matters that p is 'const', because
that restricts the usage of p inside the function body. But for a pure
function _declaration_ it does not matter whether p is declared 'const'
or not, because the caller must supply a value anyway, and what happens
to that value from the caller's perspective is the same anyway. And in
fact it's much stronger than "doesn't matter": when the compiler checks
whether two declarations are compatible it first removes top-level 'const'.

However, the 'const' for the 'int' (which is not a top-level 'const') matters
also for the declaration, because that affects what the function can do to the
'int' that the caller supplies a pointer to.

If this sounds confusing, forget it, just remember that there is something.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2

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

Similar topics

8
by: Vineet Jain | last post by:
The following does not work although it seems like something you should be able to do. def someFunction(option=Constants.DEFAULT_VALUE): Thanks, V
3
by: George Sakkis | last post by:
I'm trying to write a decorator similar to property, with the difference that it applies to the defining class (and its subclasses) instead of its instances. This would provide, among others, a way...
4
by: JR | last post by:
Hey all, I am passing a two dimensional array to a function. It basically looks like this int test(double array2 , const CONST1, const CONST2) { int returnValue; for (int i = 0;...
26
by: G Patel | last post by:
Hi, I'm wondering if anyone knows if the following function will function properly as a set-bit counter on non 2s complement machines (as K&R2 implies). | int bitcount(unsigned x) | { | ...
5
by: Pete | last post by:
I having a problem reading all characters from a file. What I'm trying to do is open a file with "for now" a 32bit hex value 0x8FB4902F which I want to && with a mask 0xFF000000 then >> right...
8
by: Davíð Þórisson | last post by:
Emm, being a newbie to C#, can someone explain to me what is the difference between a constant (as a Class member) and a read only property?? Also I simply cannot grasp the concept of static...
22
by: Brad | last post by:
Hi, Am trying to read one byte at location 0xFFF0 000E in an embedded system. I cast a pointer to int, then try to stuff the above address in, then reference whats at the location? wont...
6
by: bill | last post by:
Thanks to those that taught me to use heredoc to embed html in php. I don't want to start the html in php vs php in html discussion again., heredoc works a treat for that which I am doing...
83
by: Anonymous | last post by:
Came across some code summarized as follows: char const* MyClass::errToText(int err) const { switch (err) { case 0: return "No error"; case 1: return "Not enough"; case 2: return "Too...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.