473,804 Members | 3,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the proper Syntax for this Pointer?

What I am doing wrong

This works

batPointer = adaptors[position].adaptor[channel]->batData;
adaptors[position].batteries[channel] = batPointer->battery;

where:
batData is a pointer to a struct
batPointer is a pointer to a different kind of struct

I want one line, but I get compiler errors, what is the correct syntax?
Nov 29 '07 #1
7 2635
Neil wrote:
What I am doing wrong

This works

batPointer = adaptors[position].adaptor[channel]->batData;
adaptors[position].batteries[channel] = batPointer->battery;

where:
batData is a pointer to a struct
batPointer is a pointer to a different kind of struct

I want one line, but I get compiler errors, what is the correct
syntax?
Please post a complete, minimal program that exhibits the concerned
error. Without precise definitions
of 'batPointer', 'adaptors', 'position', 'channel', 'batData',
and 'battery', we cannot say what the problem could be.

Nov 29 '07 #2
Neil wrote:
What I am doing wrong

This works

batPointer = adaptors[position].adaptor[channel]->batData;
adaptors[position].batteries[channel] = batPointer->battery;

where:
batData is a pointer to a struct
batPointer is a pointer to a different kind of struct

I want one line, but I get compiler errors, what is the correct syntax?
What was your one line, what were the declarations of the variables, and
what were the compiler errors?

[I'd also be likely to introduce a name for `adaptors[position]`, since it's
duplicated. And without seeing the rest of your code, I can't tell if your
assignment above should obviously be extracted into a well-named function
of its own.]

--
Chris "in some contexts, context is everything" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Nov 29 '07 #3
Neil wrote:
....
The structs ( minus the uneeded stuff)are

struct adaptorBatteryD ata
{
struct batteryData const *battery;
};

struct adaptorData
{
struct adaptorBatteryD ata const *batData;
};

struct batteryData
{

};

struct adaptorBatteryD ata const *batPointer;
adaptors[position].batteries[channel] =
adaptors[position].adaptor[channel].batData->battery;
Gives the error "structure required on left side of . or *."
What is missing from what you just gave us is the data type for
adaptors[position] and adaptors[position].adaptor[channel]. As written,
your code requires that they both be structures. The message that was
generated implies that at least one of those expressions is a pointer to
a structure. If that is the case, then the your problem is due to the
fact that you've used "." rather than "->".
Nov 30 '07 #4
Neil <Ne*******@worl dnet.att.netwri tes:
Tomás Ó hÉilidhe wrote:
>Neil:
>> batPointer = adaptors[position].adaptor[channel]->batData;
adaptors[position].batteries[channel] = batPointer->battery;

I want one line, but I get compiler errors, what is the correct syntax?
[...]
>>
adaptors[position].batteries[channel] = adaptors[position].adaptor
[channel]->batData->battery;
I thought that, but then though it wrong. Thanks for the answer. And
the tip.

I hated to leave the two line solution.
Why? Is there some virtue in putting as much stuff as possible on one
line?

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Nov 30 '07 #5
On Thu, 29 Nov 2007 03:42:51 -0500, Neil <Ne*******@worl dnet.att.net>
wrote:
>What I am doing wrong
What is your end objective? What are really trying to accomplish?
>
This works
How can it work if you get compiler errors?
>
batPointer = adaptors[position].adaptor[channel]->batData;
adaptors[position].batteries[channel] = batPointer->battery;

where:
batData is a pointer to a struct
batPointer is a pointer to a different kind of struct
If batPointer is of type struct x* and batData is of type struct y*,
they are incompatible and there is no implicit conversion between
them. The only way to assign a value of one type to an object of
incompatible type is with a cast. However, if the converted pointer
value does not have the proper alignment you have invoked undefined
behavior.

Why do you want a pointer to some object to hold the address of an
object of different type?
>
I want one line, but I get compiler errors, what is the correct syntax?
One line of what? You have two independent assignment statements. Do
you intend to eliminate one?

Remove del for email
Dec 1 '07 #6
On Fri, 30 Nov 2007 02:53:53 -0500, Neil <Ne*******@worl dnet.att.net>
wrote:
snip
>Yes it works. The structures are elaborate ( Not mine ) but they do
want the are supposed to. Same the adapter, and the battery from the
linked list.

The structs ( minus the uneeded stuff)are
Unfortunately, also minus some needed stuff.
>
struct adaptorBatteryD ata
{
struct batteryData const *battery;
};

struct adaptorData
{
struct adaptorBatteryD ata const *batData;
};

struct batteryData
{

};

struct adaptorBatteryD ata const *batPointer;
adaptors[position].batteries[channel] =
You have not told us what type of struct the object adaptors is a
pointer to or an array of. The underlying structure apparently has a
member named batteries which does not match any of the three
structures you listed.
>adaptors[position].adaptor[channel].batData->battery;
It apparently also has a member named adaptor which also doesn't match
any of the three structures you listed. But adaptor appears to be an
array of or a pointer to struct adaptorData since it has a member
named batData.

batData is a pointer to struct adaptorBatteryD ata which does have a
member named battery. This member is a pointer to struct
batteryData.

So the first question: Is the undefined member batteries an object of
a suitable type so batteries[i] can receive a value of type pointer to
struct batteryData?
>Gives the error "structure required on left side of . or *."
C doesn't have an operator "*.". It does have two operators "*" but
neither one is applied to structures.

So the second question: What is the correct text of the error message?
Use cut and paste; don't retype.

And the third question: Which of the objects adaptors[i]. or
adaptor[i] is not a structure?
Remove del for email
Dec 2 '07 #7
Barry Schwarz wrote:
On Thu, 29 Nov 2007 03:42:51 -0500, Neil <Ne*******@worl dnet.att.net>
wrote:
>What I am doing wrong

What is your end objective? What are really trying to accomplish?
The pointer was use to search a linked list, If it fails I need the
first item as a place holder.
>This works

How can it work if you get compiler errors?
The two lines worked fine, When I tried to combine them I got the errors.
>
> batPointer = adaptors[position].adaptor[channel]->batData;
adaptors[position].batteries[channel] = batPointer->battery;

where:
batData is a pointer to a struct
batPointer is a pointer to a different kind of struct

If batPointer is of type struct x* and batData is of type struct y*,
they are incompatible and there is no implicit conversion between
them. The only way to assign a value of one type to an object of
incompatible type is with a cast. However, if the converted pointer
value does not have the proper alignment you have invoked undefined
behavior.
struct x* contains a pointer to a linked list of struct y* (struct x* is
also a linked list)
->a->b->c->d->NULL
| | | |
1 1 1 1
| | |
2 2 2
| |
3 3
>
Why do you want a pointer to some object to hold the address of an
object of different type?
>I want one line, but I get compiler errors, what is the correct syntax?

One line of what? You have two independent assignment statements. Do
you intend to eliminate one?
No combine
>
Remove del for email
The earlier suggestion worked fine. Thanks to all.
Besides learning the pointer, I learn that I need to include more in a post.
Dec 5 '07 #8

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

Similar topics

2
16248
by: CoolPint | last post by:
Can anyone clearly explain the difference between constant reference to pointers and reference to constant pointers? What is const int * & ? Is it a constant reference to a pointer to an integer? Or Is it a reference to a pointer to a constant integer? What is being constant in this case? The pointer or the integer being pointed? How about int * const & ? Is this a reference to a constant pointer to an integer? Or
121
10196
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
2
3686
by: Kevin | last post by:
I am currently importing data into Access 2002 from 3 Sybase ASA 7.0 databases over a network. At this time I am using a ODBC System DSN connection using the proper ASA 7 driver. I would like to be able to make a DSN-Less connection so that my software is not dependent on having ODBC set-up with proper drivers and information. I have done hours of searching/testing but have been unsuccessful at making a DSN-Less connection. Could...
140
7922
by: Oliver Brausch | last post by:
Hello, have you ever heard about this MS-visual c compiler bug? look at the small prog: static int x=0; int bit32() { return ++x; }
1
1058
by: Frank | last post by:
Hi, classTeacher contains a list of classChild ClassChild contains methods, props and so on Most things a classChild can do on its own. But AskPermission cannot be done by the Child, but must be done by the teacher. Child has to ask its teacher to do that. Is it a proper OO way to have a reference to the teacher to call a teachermethod? Thanks
10
3237
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
37
5481
by: Egbert Nierop \(MVP for IIS\) | last post by:
In win32 mode, a BSTR was UINT length prefixed and terminated exactly by a zero char. So if you allocated "Hello World" that would allocate 28 bytes. In x64 and (IA64 as well) it would become 32 bytes, because of the fact that a pointer, is 8 bytes instead of 4 bytes. The length prefix -still- is a UINT however and not a UINT_PTR.
18
2528
by: raghu | last post by:
hello, Iam going through a document contianing C tricks .In it they used the statement in many places i didn't understand can u please tell me the meaning and how the compiler compiles it and runs it The statement is : void (* func)( SDS_UINT32 , void * ); which is a member of structure Thanks in advance Bye
89
5783
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the right thing to use for every var that holds the number of or size in bytes of things. * size_t should only be used when dealing with library functions.
0
9591
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
10594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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
10331
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
10087
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
5529
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...
1
4306
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 we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.