sizeof without parenthesis

R

Richard Heathfield

CBFalconer said:
Does this mean you've finally kicked the habit of writing if, for,
while etc. as if they were functions?

I'm a bit washed out at the moment. Flu, or something pretty close to it. So
I will quietly contemplate your question until I fall asleep. :)
 
R

Richard Tobin

I hadn't thought about this before, but I like it. In the past, I've
tended to write "sizeof(int)", but I agree that "sizeof (int)" is
better. It's not a function call, so it shouldn't look like one.

I don't see the logic of your last sentence.

The difference between a unary operator and a single-argument function
is just a matter of syntax. The grammar for unary operator
application allows it to look like a function call, so why shouldn't
it?

"if" statements are not "while" statements, but can look the same
except for the keyword. Should we adopt some syntactic convention
to make them look different?

-- Richard
 
C

Christopher Benson-Manica

Oh please. One is not more uglier than the other. It's a frickin' space for
christ's sake.

#include <stdio.h>
int main(void){const char*s="Hello,world!\n";printf(s);return 0;}

No problem, right? Those missing things are just spaces.
 
C

Christopher Layne

Christopher Benson-Manica wrote:

#include <stdio.h>
int main(void){const char*s="Hello,world!\n";printf(s);return 0;}

No problem, right? Those missing things are just spaces.

Yes. Let's expand it to extremes now. (rolls eyes)
 
K

Keith Thompson

I don't see the logic of your last sentence.

It's a matter of style, which means we will never resolve the issue.
The difference between a unary operator and a single-argument function
is just a matter of syntax. The grammar for unary operator
application allows it to look like a function call, so why shouldn't
it?

For the same reason that I prefer
return 42;
over
return(42);

I usually put spaces around operators. "sizeof" is just another
operator (even though it's the only one represented by a keyword
rather than by a delimiter), so why should it be any different?

On the other hand, I just realized that I usually *don't* put a space
after a unary operator (-x, &obj, *ptr), which weakens the argument a
bit.
"if" statements are not "while" statements, but can look the same
except for the keyword. Should we adopt some syntactic convention
to make them look different?

Absolutely. I suggest distinguishing between them by using different
keywords. :cool:}

There are several constructs in C that *can* look like function calls
at first glance, and I like to use layout tricks to make them look
different. I avoid extraneous parentheses on return statements, I
leave a space after "if" and "while", I use upper case for macros, and
so forth. Avoiding parentheses in "sizeof obj", and adding a space in
"sizeof (type)" are the same kind of thing.

Having said that, it's not a big deal. I have no problem reading
"sizeof(int)" rather than "sizeof (int)" in someone else's code
(because I *know* sizeof is an operator), but I'll probably start
using "sizeof (int)" in my own code (unless I forget).
 
A

Ancient_Hacker

Richard said:
The grammar for unary operator
application allows it to look like a function call, so why shouldn't
it?

Well sometimes visual consistency is misleading. You have to weight
the ease of reading versus hiding what's really happening. As you
probably know, there are drawbacks to having macro calls look just like
function calls-- one should be much more wary of macro calls than
fucntion calls, but their identical appeaqnce hides their differences.


Something similar might be happening with sizeof and return maskerading
as functions. This NG gets plenty of inquries about why sizeof can
take a type, when nothing else can. Mayhaps there would be less of
this kind of confusion if sizeof didnt look like a function call. Just
MHO.
 
R

Richard Tobin

"if" statements are not "while" statements, but can look the same
except for the keyword. Should we adopt some syntactic convention
to make them look different?
[/QUOTE]
Absolutely. I suggest distinguishing between them by using different
keywords. :cool:}

Likewise, I suggest distinguishing between the sizeof operator and
functions by using the "sizeof" operator name :)

-- Richard
 
D

Dave Thompson

It certainly wasn't used on regular teletypes. When using
5-level Baudot/Murray code, rubout was all marks, or
letters-shift. I think it was all marks when using 8-level code,
too, and I think the ASR-33 had a special rubout key, but I could
be wrong.

As already said, @ for line erase and # for character delete were used
in software for terminals including Teletypes, first in MULTICS and
then in Unix. Yes, 'rubout' in ASCII was 0x7F (0xFF in even parity)
and had a separate key for it on model 33 for certain and I believe
all other 8-level machines. Some computers (OSes) used rubout as
character delete (at least optionally) particularly DEC ones like
RT-11 and RSX-11*; but this was inconsistent with its use on plain
(e.g. cable) Teletype paper tape, where rubout was used to delete the
character overpunched not the preceding one.

- David.Thompson1 at worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top