473,386 Members | 1,819 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,386 software developers and data experts.

Indirection operator placement

I am wondering what is the difference in the placement between the 2
uses of the indirection operator? Or is there a difference?

AcDbBlockTable *pBlockTable = NULL;

AcDbDatabase* pDB = acdbHostApplicationServices()->workingDatabase();

Aug 21 '06 #1
5 2669

There's no difference.

Tolga Ceylan

Aug 21 '06 #2
Marty posted:
I am wondering what is the difference in the placement between the 2
uses of the indirection operator? Or is there a difference?

AcDbBlockTable *pBlockTable = NULL;

AcDbDatabase* pDB = acdbHostApplicationServices()->workingDatabase();

A C++ compiler ignores white space, so it sees all of the following
identically:

int*p=0;
int *p=0;
int* p = 0;
int * p = 0 ;

I think it's intuitive, however, to write it as follows:

int *p = 0;

, because it conveys that the asterisk is a part of the object's name --
which is how things actually work:

int *p, *q, r[5], (*s)[5], *t[5], Func(), *Func2(), (*Func3())[5];

p is a pointer.
q is a pointer.
r is an array of 5.
s is a pointer to an array of 5.
t is an array of 5 pointers.
Func is a function which returns an int.
Func2 is a function which returns a pointer to an int.
Func3 is a function which returns a pointer to an array of 5.

--

Frederick Gotham
Aug 21 '06 #3

"Marty" <mc******@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>I am wondering what is the difference in the placement between the 2
uses of the indirection operator? Or is there a difference?

AcDbBlockTable *pBlockTable = NULL;

AcDbDatabase* pDB = acdbHostApplicationServices()->workingDatabase();
I assume you're talking about the "*" symbols in the code above? That's not
an operator. It specifies that the object being declared is a pointer to
the type specified on the left of the * symbol. The spacing is irrelevant.
The following are all the same:

int* pInt;
int *pInt;
int * pInt;
int * pInt;

All those line declare a variable named pInt whose type is "pointer-to-int".

Some people prefer to put the * immediately after the type, others prefer to
put it immediately before the identifier, and still others prefer to put
spaces on both sides.

The compiler doesn't care one way or the other. :-)

-Howard
Aug 21 '06 #4
Marty <mc******@gmail.comwrote:
I am wondering what is the difference in the placement between the 2
uses of the indirection operator? Or is there a difference?

AcDbBlockTable *pBlockTable = NULL;

AcDbDatabase* pDB = acdbHostApplicationServices()->workingDatabase();
This is answered on Stroustrup's FAQ:
http://www.research.att.com/~bs/bs_faq2.html#whitespace

In short, they are the same. It's merely a matter of style which form
you use. However, as noted on the referenced page, the confusion comes
when someone tries to declare multiple pointers with a single
declaration:

int* p1; // pointer to int
int *p2; // also pointer to int

int* p3, p4; // p3 is a pointer to int, p4 is a regular int
int* p5, *p6; // both p5 and p6 are pointers to int

Since I prefer one declaration per line, this doesn't affect me, so I
use the (int* p;) form instead of the (int *p;) form, for the reason
given on the page: (int* p;) emphasizes the type (p is a pointer to
int), versus (int *p;) which emphasizes the syntax (*p is an int).

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Aug 21 '06 #5

Thanks all!
I am new to C++ (if you can't tell) but you confirmed what I thought
was the answer.
When I started looking through the example project, they used it as I
had shown.
It started to get me to double guess myself.

Aug 21 '06 #6

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

Similar topics

20
by: Ioannis Vranos | last post by:
When we use the standard placement new operator provided in <new>, and not a definition of owr own, isn't a call to placement delete enough? Consider the code: #include <new>
5
by: kUfa.scoopex | last post by:
Hi there! I have a small problem, and i really dont see any convenient way to fix it. Basically, i'd like to overload global new operators, into something like this: void *operator new(...
6
by: YUY0x7 | last post by:
Hi, I am having a bit of trouble with a specialization of operator<<. Here goes: class MyStream { }; template <typename T> MyStream& operator<<(MyStream& lhs, T const &)
19
by: santosh | last post by:
Hi all, In the following program I allocate a block of pointers to type char, initialised to zero. I then point each of those pointers to a block of allocated memory of fixed size (33 bytes). A...
2
by: Mark P | last post by:
Consider a class in which I redefine operator new(std::size_t): struct A { void* operator new(std::size_t size) {/* my implementation */} }; This has the consequence of hiding the placement...
15
by: mangesh | last post by:
This code is from c++ faq in section 11 : void someCode() { char memory; void* p = memory; Fred* f = new(p) Fred(); f->~Fred(); // Explicitly call the destructor for the placed object }
6
by: Angus | last post by:
I am using a global which is a void* I have it defined in one file as: void* hFlag; and one other header file as: extern void* hFlag; But I get this compile error:
13
by: JD | last post by:
Hi, My associate has written a copy constructor for a class. Now I need to add an operator = to the class. Is there a way to do it without change her code (copy constructor) at all? Your help...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.