#qi-hardware IRC log for Monday, 2013-03-25

whitequarkwhy is that ASIC miner even a part of qi-hw wiki?..06:50
kyaki just discovered the older syntax for function definition: "The parameters are named between the parentheses, and their types are declared before16:14
kyakopening the left brace"16:14
whitequarkK&R, yes16:15
kyaki found it more convenient for functions with many arguments, because it is easier to edit and change arguments types16:15
larscit's horrible, in my opinion16:16
kyakbut i wonder hwo portable is it? it is supported by gcc is all i know16:16
whitequarkthe historical context is that back in the days, everything was `int`.16:16
whitequarkso you didn't really specify any types.16:16
larscI think gcc will tell you that it's bad idea to do this16:16
whitequark(by default, that is)16:16
whitequarkreturn types, argument types, even variable types16:16
whitequarkmain; is valid C8916:16
kyakgcc just silently "eats" it16:16
larsckyak: -Wall -pedantic, etc16:16
whitequark(and is equivalent to `int main`)16:16
wpwrakgcc can issue warnings for such things. some old-style definitions can also cause real trouble.16:17
kyakbut how convenient it is! you can say int param1, param2 instead of int param1, in param216:18
wpwrake.g., you can declare a function just as extern int blabla(); ("extern" and "int" are both optional, but gcc can complain if you omit the "int")16:18
larsckyak: you can even say param1, param216:18
wpwrakthis would then be compatible with any (!) list of arguments. so you lose all checking and all type conversion as well.16:18
kyakno, i'm only talking about definition.. i understand it is bad for declaration16:18
larscwithout any int at all16:18
kyaklarsc: do you mean, in old style?16:19
larscas whitequark everything is an int by default16:20
larscas whitequark said16:20
wpwrakin a way ... i think pointers were special. not sure how they actually implemented them. they probably assumed that sizeof(pointer) <= sizeof(int)16:22
whitequarkwpwrak: =16:22
whitequarkint = ptr = machine word16:22
wpwrakand char just became an int16:23
whitequarkafaik16:23
kyakyep, i use just (param1, param2) in definition. But if i wanted to make them chars, char param1, param2 before the left brace is more compact than (char param1, char param2). Again, i'm only talking about the definition16:23
wpwrakwhitequark: ah, there are subtleties. e.g., you could have different kinds of pointers. e.g., if your machine had a memory for numbers and another memory for characters, you'd have quite different pointers16:24
larscdid you know that the c standard differentiates between function pointer size and data pointer size?16:24
wpwrakof course, this sort of architectures is pretty much extinct now16:24
larscgcc will throw a warning if you assign a function pointer to a data pointer16:24
whitequarklarsc: yes, of course16:24
whitequarkthat's still useful e.g. AVR16:25
whitequarkbut I'm not sure if it was in K&R C16:25
whitequarkdunno about the PDP-7 arch16:25
kyakbtw, i like it how how they get through the first chapter (Introduction) of K&R without using pointers at all16:26
kyakthe example programs are very simple of course, but still16:26
larscthey get through entire java books without using pointers at all ;)16:29
whitequarkdon't mention java16:30
whitequarkplease16:30
larscprobably ruby books as well16:30
whitequarkhrm16:30
whitequarkyou get exposed to indirection pretty quickly in ruby16:30
whitequarka = []; b = a; b << 1; a # => [1]16:30
whitequarkat this point people usually come to #ruby-lang and ask questions.16:31
wpwrakhaving to confront unpleasant truths early helps to strengthen the character :)16:32
whitequarkoh exactly16:32
larsclike there is no santa16:32
larscor easterbunny16:32
larscto stay in the season16:32
whitequarkwhat season16:32
Action: whitequark looks at piles of snow 2m high16:32
whitequarkit *is* decemper16:33
larscyou only need to go the nearest supermarket16:33
whitequark*december16:33
whitequarkall the clocks are simply wrong16:33
kyak"Call by value is an asset, however, not a liability." - i'm quoting K&R :)16:34
whitequarkcall by value is pretty much a requirement for any systems programming16:35
kyakwhitequark: don't look at my piles! they are mine! mine!16:35
whitequarkthe first thing they did to haskell in order to adopt it to systems programming (Habit) was to make it call-by-value16:35
whitequarkalso call-by-name coupled with pervasive side effects is a disaster16:35
whitequarkdemonstrated by, I think, ALGOL16:35
larscwhitequark: what do you mean by systems programming?16:36
whitequarklarsc: that is a broad topic. but if you need to be able to talk directly to hardware, that's systems programming.16:42
whitequarksame for manually managing memory.16:42
larscwhy do you need call by value for that?16:42
kyakmakes me wonder, why C function can't return two arguments - one has to use pointers for that. Why not simple make C a pass-by-reference language then? Especially considering the extensive use of pointers in C16:43
whitequarklarsc: call-by-name is essentially lazy evaluation, and most of the aforementioned code depends on side effects being executed in accurate order16:43
larscah ok16:44
larsci see16:44
larsckyak: I think the biggest problem with that is that you'd need to update the ABI for every single architecture16:44
kyakotherwise, C is pass-by-value for input arguments and pass-by-reference (kind of) for output16:45
whitequarkkyak: pass-by-reference?16:45
whitequarkC is strictly pass-by-value16:45
kyakwhitequark: that's why a said "kind of".16:45
kyakyou need to use pointers if you need more than one output16:45
whitequarkstruct { int a; int b} f()16:46
kyakok, if you need to scalar outputs16:46
kyakyou understand what i mean, don't suggest me your little tricks :)16:46
kyakalso, if it's pass-by-value, what i can't pass the array value? 16:47
whitequarkbecause there are no array values16:47
kyakas input16:47
whitequarkstruct { int a, b; } foo() { struct {int a, b; } foo = { 0, 0 }; return foo;16:48
whitequark}16:48
whitequarkgcc is extra helpful here:16:48
whitequarktest.c:3:3: error: incompatible types when returning type struct <anonymous> but struct <anonymous> was expected16:48
wpwrakit's not a trick :)16:48
whitequarkclang:16:48
whitequarktest.c:3:10: error: returning 'struct <anonymous struct at test.c:2:3>' from a function with incompatible result type16:48
whitequark      'struct <anonymous struct at test.c:1:1>';16:48
whitequark  return foo;16:48
whitequark         ^~~16:48
whitequarkkewl, you can do this:16:49
whitequarktypedef struct { int a, b; } ret_t;16:49
whitequarkret_t foo() { return (ret_t) { 0, 0 };16:49
whitequark}16:49
wpwrakjust declaring struct foo wuold also do the trick ...16:50
wpwrakthere's nothing magic here16:50
whitequarkwpwrak: then I'd have to do `return (struct ret_t)` for C89 compat16:50
whitequarkI think16:50
whitequarkI thought I could do that in-line. LLVM IR can do this:16:51
whitequarkret { i32, i32 } { 0, 0}16:51
wpwrakthat looks very wrong16:52
whitequarkwell, LLVM has strictly structural typing16:52
wpwrakand you'd have to .... struct ret_t ret; ... return ret;16:52
whitequarkI'm not sure about C spec...16:53
whitequarkwpwrak: yeah.16:53
wpwrak(return is not a function - no parentheses needed)16:53
whitequarkum, that is not a "method call"16:53
whitequarkit's a type conversion16:53
whitequarkI could also write it as ret_t({ 0, 0 })16:53
whitequarkbut not ret_t { 0, 0 }16:53
whitequarktest.c:3:10: error: expected expression return struct ret_t { 0, 0 };16:54
larscI think (ret_t) {0, 0} is gcc extension16:54
wpwraklooks like a logical extrapolation from aggregate initializers16:55
whitequarkboth gcc and clang eat (struct ret) { 0, 0 } in --std=c8916:56
whitequarkoh -pedantic suggests it's C9916:56
larscah ok16:57
kyakso i can pass arrays by value.. just need to wrap them into a structure?17:02
larscyes17:04
whitequarkyep17:05
kyakam i the only one finding the pass-by-value concept of C inconsistent? I'm talking about inconsistency between inputs and outputs of a function17:05
wpwrakyou mean the number of things you can pass in/out ? or what kind of things you can pass in/out ?17:07
whitequarkthat you cannot have more than one return value?17:07
whitequarkyeah, more recent languages all have this built-in17:08
whitequarkLua, Ruby, Python, etc17:08
whitequarkLisp could simply return a list17:08
kyakyeah, i'm talking about the number of outputs17:08
whitequark(actually, Ruby and Python do that, too. it's just Lua who has native multi-return support)17:08
whitequark(R&P also have deconstructing assignment for arrays/tuples.)17:08
whitequarka, b, c = [1, 2, 3]17:09
whitequarkor a, b, c = get_multi17:09
kyakyeah, many languages do that.. MATLAB does that17:09
kyakand then there are "exceptions". When you pass an array name to C function, you get the address. I mean, isn't it just another proof that passing by reference would make more sense?17:12
kyakand then you can suddenly subscript that value using square brackets.. But hey, it's an address!17:14
whitequarksquare brackets do not exist.17:15
whitequarksubscripts, also.17:15
whitequarkit is a syntactic sugar for addition.17:15
kyaki see.. sugar is not healthy :)17:17
larscsyntacitc sugar for addication ;)17:17
larscsyntactic sugar for addicition17:17
whitequarkaddiction?17:18
larscso you get addicited to using the language17:18
kyakyou just can't get that word right, can you? :)17:19
larsctoo much sugar17:19
larsccan type anymore17:19
larsccant17:19
whitequarkrofl17:20
kyakdo you advise against using square brackets, but rather use pointers?17:20
whitequarkkyak: why? it's the same thing17:20
larscit's not17:20
whitequarkif square brackets make your code more clear (they do), use them.17:20
whitequarklarsc: how so?17:20
kyakwhitequark: dunno, it sound bad the way you said it17:20
larscwhitequark: can't remember ;)17:21
kyak"When you use the type char x[] instead of char *x with initialization, they are completely 100% different."17:23
kyakhttp://stackoverflow.com/questions/1790704/difference-between-square-brackets-and-asterisk17:23
whitequarkum, [] do not mean "subscript" in declaration17:23
kyakbut i think in the context of array subscript, they are the same17:24
whitequarkthat is true, of course. I was only talking about operator [], not the declaration syntax.17:24
kyakwell, at least now i start to understand where aware-of-ASCII-only programmers come from. It's clear K&R didn't think of "wide characters" at that time, but so do many developers not think about it now.17:30
whitequarkEnglish-centered world.17:31
whitequarkhehe I just learned about the new hotness, FRP18:40
whitequarkfunctional reactive programming18:40
whitequarkimagine a verilog simulator. now replace "wires" with "signals", "pins" with "events" and "triggers" with "switches"18:41
whitequarkthen connect the whole thing to a GUI18:41
whitequarkI think the history has just looped.18:41
whitequarkwe had physical buttons and physical lamps connected by physical wires18:42
whitequarknow we have virtual buttons and virtual lamps connected by virtual wires.18:42
larscjust wait until somebody adds a virtual transistor18:54
whitequarkall already there18:54
whitequarkhttp://elm-lang.org/edit/examples/Reactive/Clock.elm18:54
larscbut gui toolkits like gtk and qt had this for ages18:54
whitequarklarsc: FRP seems like a higher level abstraction to me.18:55
whitequarkyou know, you could say that C has first-class functions because it has function pointers.18:55
larscyes18:55
whitequarkthis sort of distinction.18:55
whitequarkwpwrak: did you mention a language called Esterel?19:08
whitequarkor whatever else, suited to synchronous programming?19:08
whitequarkI vaguely recall we've had a conversation about them19:08
wpwraki plead "not guilty"19:09
wpwrakmay have been DocScrutinizer05. he's come into contact with some very strange languages.19:10
whitequarkwpwrak: it *definitely* were you19:11
whitequarkbut I'm not sure about the name of the language19:11
DocScrutinizer05wouldn't recall anything like that19:12
DocScrutinizer05erlang?19:12
DocScrutinizer05prolly not19:13
whitequarkno no, I know what erlang is :p19:13
whitequarkwpwrak: might have something to do with CSP19:13
whitequarkas in communicating sequental processes19:13
whitequarkit was a discussion about parallelism...19:13
whitequarkoccam? probably no19:14
wpwrakhmm, erlang then ?19:17
wpwrakah no19:17
wpwrakhmm. pearl ? that would have been DocScrutinizer05, though19:17
DocScrutinizer05is pearl "suited to synchronous programming"?19:18
wpwrakif it's turing-complete, it probably is ;-)19:19
DocScrutinizer05lol19:19
DocScrutinizer05if in doubt, try ada19:20
DocScrutinizer05ada is everything, plus some cruft on top ;-)19:20
whitequarkpearl seems relevant, but it's not that.19:20
whitequark(ada) yeah :D19:20
whitequarkand so much syntax you'd want to strangle yourself19:20
--- Tue Mar 26 201300:00

Generated by irclog2html.py 2.9.2 by Marius Gedminas - find it at mg.pov.lt!