ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.

Having a problem logging in? Please visit this page to clear all LQ-related cookies.

Introduction to Linux - A Hands on Guide

This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.

I could have said "Google", but Google does not like that phrase by itself.

Found after some Googling (assuming you meant in the C language):

Quote:

In fact, an expression involving the member-selection operator (->) is a shorthand version of an expression using the period (.) if the expression before the period consists of the indirection operator (*) applied to a pointer value. Therefore,

Thanks, Wim! I was wondering what kind of variable rsrc could be, to be honest; couldn't find it declared in any of the source or header files linking to the source. That's not to say it's not defined somewhere, just that I hadn't found it.
Pixellany, I tried Googling as well and found the same problem. Have since found out '->' is a 'postfix' operator (whatever that is). Some kind of bitwise variant, I guess.

Thanks, Wim! I was wondering what kind of variable rsrc could be, to be honest; couldn't find it declared in any of the source or header files linking to the source. That's not to say it's not defined somewhere, just that I hadn't found it.
Pixellany, I tried Googling as well and found the same problem. Have since found out '->' is a 'postfix' operator (whatever that is). Some kind of bitwise variant, I guess.

i dont thin -> is a postfix operator
it accesses a member of a pointer to a structure

A postfix operator has one operand and the operator comes after the operand.
A prefix operator has one operand and the operator comes before the operand.
An infix operator has two operands and the operator comes between the operands.

-> has two operands (a pointer and a field name) and the -> operator comes between the two operands.

Quote:

Some kind of bitwise variant.

I think you are confused over the fact that C and C++ support implicit casts to true/false when values that are not boolean are used in places such as if conditions.

From the original snip of code there is no reason to suspect that rsrc->outfile is a boolean value. rsrc is a pointer to some kind of structure and outfile is the name of some field of that kind of structure. The type of rsrc->outfile is the type of whatever is that named field in that kind of structure.

In my opinion, it is wrong. But the question is slightly tricky. There is a fundamental difference between the right hand "operand" of the ordinary infix operators and the right hand operand of -> or .

An ordinary operand can be replaced by an expression in () that evaluates to the correct kind of thing.

But the right hand operand of -> or . must directly be the right kind of thing (a field name in the correct structure). There is no support for it to be an expression evaluating to the right thing.

(In C++ there are alternate versions ->* and .* which are ordinary infix operators in the sense that the right hand operand could be an expression evaluating to the right kind of thing.

So, if you took a stricter view of the meaning of "operand" then -> or . could not be called infix operators.

Even with that view, you couldn't call -> or . postfix operators. Instead, in your original example of rsrc->outfile you would call ->outfile a postfix operator.

It is clearer to call -> or . infix operators that happen to have the same operator precedence as the true postfix operators (the other items listed on that line).

You were right. It is indeed a 'structure access operator' as you and some others here asserted. I finally found what follows from some obscure site and post it here for clarification:

Quote:

Selection (structure-access) operators ('.' and '->')

The C language supports two selection operators:

. (direct member selector)
-> (indirect, or pointer, member selector)

You use the selection operators '.' and '->' to access structure and union members. Suppose that the object s is of struct type S and sptr is a pointer to s. Then, if m is a member identifier of type M declared in S, these expressions:

s.m
sptr->m

are of type M, and both represent the member object m in s.

The expression

sptr->m

is a convenient synonym for (*sptr).m.

The direct member selector ('.') uses the following syntax:

expresssion . identifier

The expr must be of type union or structure. The identifier must be the name of a member of that structure or union type.

The indirect member operator ('->') uses the following syntax:

expr -> identifier

The expr must be of type pointer to structure or pointer to union. The identifier must be the name of a member of that structure or union type.

The expression with selection operators designates a member of a structure or union object. The value of the selection expression is the value of the selected member; it will be an lvalue if and only if the expr is an lvalue. For example,

struct mystruct
{
int i;
char str[21];
long d;
} s, *sptr=&s;

...

s.i = 3; // assign to the 'i' member of mystruct 's'
sptr->d = 12345678; // assign to the 'd' member of mystruct 's'

The expression 's.m' is an lvalue, provided that 's' is an lvalue and 'm' is not an array type. The expression 'sptr->m' is an lvalue unless 'm' is an array type.

If structure B contains a field whose type is structure A, the members of A can be accessed by two applications of the member selectors.