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

function arguments()

Name: Anonymous 2010-04-24 9:47

Which do you prefer:


int foo(int a);
int foo(int a = someDefaultArgument);


or

int foo(int a);
int foo(void);

Name: Anonymous 2010-04-24 10:04

>>1
Why would you have such a retarded overload scheme in the first place? The point of overloading is not to cram as much shit into the same function names as possible; it's to allow for functions with the same purpose to accept different types and act accordingly.

You should have one function definition; that being int foo(int a = some_default_argument); If you absolutely must have a default form of the function, it depends on See or Sepples.

With See, you would use void. With Sepples, you would use nothing.

Name: Anonymous 2010-04-24 14:34

Let's try something:
I am using a library with this function.
int foo( int a = 3, int b = 5 );
- I'd really like to specify b as 6.
- I also really need to use the default value for a.
- I don't know the default value for a.
- All numbers are valid inputs for each argument.
Question: How do I call this function?

Name: Anonymous 2010-04-24 15:02

>>3
If you were using Python, you'd write foo(b = 6).

Name: Anonymous 2010-04-24 17:12

>>4
no, you'd write foo(b=6), because Guido doesn't like spaces between default values in a function definition or call.

Name: Anonymous 2010-04-24 19:35

>>5
Fuck you, I'll do what I want.

Name: Anonymous 2010-04-24 19:45

>>3
Simple, just declare a public const int DEFAULT_VALUE_FOR_PARAMETER_a_IN_FUNCTION_foo = 3;

Name: Anonymous 2010-04-24 19:48

>>6
Fuck you, I won't do what you tell me

Name: Anonymous 2010-04-24 20:01

>>5
Nitpick: b = 6 is not a (the) default value.

Name: Anonymous 2010-04-24 20:49

struct foo {
    foo() : a_(3), b_(5) { }

    foo a(int value) { foo x = *this; x.a_ = value; return x; }
    foo b(int value) { foo x = *this; x.b_ = value; return x; }

    void operator() () {
        // Do something with a_ and b_
    }

private:
    int a_, b_;
};

foo().b(6)();


SEPPLES QUALITY

Name: Anonymous 2010-04-24 20:56

void operator() () () () ()

Name: Anonymous 2010-04-24 21:03

>>3
just fix the
- I don't know the default value for a.
part by reading the documentation for the library.

Name: Anonymous 2010-04-24 21:55

>>12
But then you're hardcoding that value, which nullifies the benefit of it being the default value. Hope it doesn't ever need to be changed later!

Name: Anonymous 2010-04-24 23:14

>>13
Yeah my bullshit is a little rusty. Could you go over how to use a non-constant default parameter again?

Name: Anonymous 2010-04-25 0:10

>>14
By editing the file that defines it, dumbass.

Name: Anonymous 2010-04-25 0:20

>>15
Then the const solution is fine, dumbass.

Name: Anonymous 2010-04-25 0:29

>>16
Good luck finding every separate instance where you explicitly wrote the default value out.

Name: Anonymous 2010-04-25 1:08

>>17
You mean the one place it's defined? Yeah, no, that's not a problem. Not to mention: if your default values change and it alters the behavior of everything that calls it with the old default value then you have a serious issue on your hands and all calls to that function need to be revisited to ensure they still perform as expected.

Name: Anonymous 2010-04-25 9:41

>>3
Simple: You don't do that. Stop being retarded. Stop it now!

Name: Anonymous 2010-04-25 10:15

>>18
and it alters the behavior of everything that calls it with the old default value
That's exactly what I was referring to, you aspie fuck.

Name: Anonymous 2010-04-25 14:58

Is it possible to programatically vary parameters in C from the caller side? (for the calee side you can use the varargs macros)

Example: you want to read from a file a dynamic library name, a function name, and a list of parameters it takes along with their values.

You use a system call to load the library. You use another to get a function pointer to the function by name. But now, how do you call it? (you didn't know the number or types of the parameters at compile time)

Bonus points if you can even specify the calling convention.

(Of course this can be done with inline assembly, but there must be a portable way - many interpreted languages whose interpreters are written in C allow this)

Name: Anonymous 2010-04-25 15:12

>>21
A switch statement? Lol I dunno.

Name: Anonymous 2010-04-25 15:14

>>21
I'd just use assembly for that, it's really straightfoward to do it that way. Although, you can do some stackrobatics, just as easily in C, as long as you don't mind slightly exposing some implementation details (the same that varargs expose, just look at how they're implemented - they're pretty simple macros which manipulate the stack).

Name: >>23 2010-04-25 15:16

Of course, there's also the issue of properly following the calling convention/doing cleanup. A bruteforce approach would be to save/restore the stack pointer before/after call, but that's a pretty rough way to do it.

Name: Anonymous 2010-04-25 15:40

>>20
What's your point then? You have to go revisit every call you made to that function in that case anyway.

Name: Anonymous 2010-04-25 16:58

>>25
Not if you don't hardcode the default value everywhere.

Name: Anonymous 2010-04-25 17:38

>>26
It doesn't matter. Once the meaning of the function changes that much, every call to it is suspect, no matter what you gave it before.

Name: Anonymous 2010-04-26 9:14

>>27
If changing the default is changing the meaning of your function, you need to put more thought into how you're structuring your API.

Default value means "I don't care what this value is." If it matters to the caller, specify the value.

Name: Anonymous 2010-04-26 10:29

SPECIFY MY ANUS

Name: Anonymous 2010-04-26 13:23

>>29
I think you're in the wrong board mate.

http://en.wikipedia.org/wiki/Progressive_rock

Progressive rock (also referred to as prog rock or /prog/) is a subgenre of rock music[1]  that developed in the late 1960s and early 1970s as part of a "mostly British attempt to elevate rock music to new levels of artistic credibility."[2]

[1] Listening to the future: the time of progressive rock, 1968-1978, pp. 71-75
[2] "Prog-Rock/Art Rock". AllMusic. AllMusic. 2007. http://allmusic.com/cg/amg.dll?p=amg&sql=77:374. Retrieved 2007-12-04.

Name: Anonymous 2010-04-26 14:10

>>30
Ah thanks yes I was trying to raise awareness of cult 60s prog rock group "SPECIFY MY ANUS", but clearly this was the wrong foum

Name: Anonymous 2011-02-03 6:26

Name: Anonymous 2011-02-17 20:16

that's cool and all, but check 'em

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