Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C89 structs

Name: Anonymous 2010-08-30 0:37

Hi /prog/. When I program C I usually just use whatever features gcc allows without really worrying about different standards. However, I am now trying to learn strict C89. I know that it's no longer "standard" C, but I want to learn it anyways.

typedef struct {
    int a, b;
} s;


So normally, if I wanted to return an s from a function I would just use return (s) {1, 2};, but apparently that's not allowed in C89. So right now I'm using
s res;
res.a = 1;
res.b = 2;
return res;


Is there a better/shorter way to do this?

Thanks.

Name: Anonymous 2010-08-31 5:36

>>40
implying your post is going to cause anything but more of this.

Name: Anonymous 2010-08-31 6:04

>>41
More of this.

Name: Anonymous 2010-08-31 10:52

>>42
Less of this.

Name: Anonymous 2010-08-31 11:27

>>43
The same amount of this.

Name: Anonymous 2010-08-31 13:01

>>32
In C89 the # needs to be in the first column. You generally put the indentation after the #, and before the first identifier, so your "fucktarded" solution is actually the correct one.

Most editors will enforce this; that's why they jump to the first column when you type #.

Name: Anonymous 2010-08-31 13:30

>>44
A different amount of this.

Name: Anonymous 2010-08-31 13:38

>>45
I'm glad we aren't stuck using C89 then.

Name: Anonymous 2010-08-31 14:13

>>48
Not Emacs.

Name: Anonymous 2010-08-31 14:42

>>48
I bet it's these brain-rotting §§IDE''s.

Name: Anonymous 2010-08-31 15:20

>>50
§§
FFFFFFFFFFFFFFFFFFFFFFFFF I MAD

Name: Anonymous 2010-08-31 16:17

>>51
This is what's on my keyboard in place of the usual single opening faggot quote.

Name: Anonymous 2010-08-31 16:19

Where did >>48 go?

Name: Anonymous 2010-08-31 16:26

>>52
I remember that discussion. So are you missing any other standard keys, or is that it?

Name: Anonymous 2010-08-31 17:15

>>54
It's an Apple wireless keyboard (http://regmedia.co.uk/2010/06/09/tt_ipad_acc_3.jpg), but I cannot identify the layout.
The keyboard differs from the pictured one in that I don't have the Euro sign on the 2 key and I have the usual octothorpe on the 3 key.

Name: Anonymous 2010-08-31 18:11

>>55
http://support.apple.com/kb/HT2841
It appears to be the English (International) layout.

Name: Anonymous 2010-09-01 6:05

>>45
No it doesn't.

C89 3.8p1:

A preprocessing directive consists of a sequence of preprocessing tokens that begins with a # preprocessing token that is either the first character in the source file (optionally after white space containing no new-line characters) or that follows white space containing at least one new-line character, and is ended by the next new-line character.

Name: >>26 2010-09-01 6:40

>>57
amen

Name: Anonymous 2010-09-01 7:38

>>54
standard keys
IHBT

Name: Anonymous 2010-09-01 8:08

>>59
No, you're just a moron.

Name: Anonymous 2010-09-01 8:18

>>60
You're saying there's a standard for keyboards and their layouts and keys?

Name: Anonymous 2010-09-01 11:26

>>57
Oh interesting. So that leads to my next logical question, which is why the cock shit do editors like Xcode and Vim jump to the first column when I type #? And how the hell do I turn that off?

Name: Anonymous 2010-09-01 11:51

Name: Anonymous 2010-09-01 13:05

>>62
So that leads to my next logical question, which is why the cock shit do editors like Xcode and Vim jump to the first column when I type #?
The answer to that question led to that question? Is this a recursion joke?

Name: Anonymous 2010-09-01 13:12

>>62
Xcode does that because it's §§user-friendly''. Do you feel befriended? Like most user-friendly features of Xcode, it cannot be turned off (because why would you even want to do such a thing‽).

Name: Anonymous 2010-09-01 14:11

>>65
§§
We've been over this[b]![/b]

Name: Anonymous 2010-09-01 14:13

Enforcing LIFO tag closing structure considered harmful!

Name: Anonymous 2010-09-01 16:35

>>67
agreed

Name: Anonymous 2010-09-01 17:13

>>62
It's because the most common style for indenting preprocessor directives is to put the # in the first column. It makes it easy to see which lines are for the preprocessor while still keeping it easy to see the indentation at a glance.

Name: Anonymous 2010-09-01 17:38

This whole time I was under the impression that it was mandatory for standards-compliance. You learn something new every day I guess.

Name: Anonymous 2010-09-01 18:36

>>69
Syntax highlighting can do that too, and with less fucktardedness.

Name: Anonymous 2010-09-01 19:35

Regarding >>1, has anyone actually tested the efficiency of implementing vectors this way in C? The brevity it allows is nice.

Name: Anonymous 2010-09-01 21:27

>>72
Already answered ITT. It's a waste of stack.

Name: Anonymous 2010-09-01 22:19

>>73
Of course it uses more stack, but that doesn't mean it's slower. I'm asking if someone has actually tested it.

Name: Anonymous 2010-09-02 0:32

It doesn't necessarily use more stack. Three floats could be passed in registers...

Name: Anonymous 2010-09-02 1:22

>>75
No C ABI I'm aware of allows for any struct larger than 8 bytes to be passed in registers.

Name: Anonymous 2010-09-02 2:28

>>76
Yeah but they could be inlined. Almost all of your vector functions should be inlined anyway so your compiler can take full advantage of SIMD instructions. Can't the latest SSE set even do shit like dot products in a single instruction these days? (I'm kind of out of the loop.)

And if it is a non-trivial function, then the stack space is the least of your worries. Plus many C++ compilers are used to passing in a pointer to store the return value to avoid an extra by-value copy; there's no reason they wouldn't do the same for C.

Name: Anonymous 2010-09-02 3:46

>>77
This shit ain't being vectorized unless you do it manually.

And yes, if it's inlined obviously it won't create the useless copies. But then nothing will be "passed" to functions either.

C and C++ use basically the same semantics for returning structs, your understanding of C++ is flawed if you think it avoids the extra by-value copies with the same prototypes.

Name: Anonymous 2010-09-02 14:16

>>78
You mean the C++ FAQ Lite is lying to me?

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.9

sad trombone

Name: Anonymous 2010-09-02 14:56

>>79
http://yosefk.com/c++fqa/ctors.html#fqa-10.9

Of course our boring binary logic fails to represent the developers who think they care about performance, although they have a very vague idea about the actual performance of their programs. Those are the people who use the von Neumann model ("you access memory using pointers which are actually indexes of individual bytes") to think about computers, and call this "the low level". They are typically less aware of things like instruction caches (which make big programs slow), SIMD instruction sets (which can give performance gains way beyond "generic" template implementations of numerical algorithms), assembly language and optimizers in general (for example, how restrict helps optimization but const doesn't). These people engage in lengthy discussions about complicated high-level optimizations, their ultimate goal being very generic code which can be compiled to a very efficient program by a very smart compiler, which will never exist.
which will never exist
( ._.)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List