« first day (116 days earlier)      last day (3528 days later) » 

3:12 AM
I like C guys.
 
 
1 hour later…
ASR
4:14 AM
good morning to all
 
4:25 AM
Morning
 
 
1 hour later…
5:47 AM
morning, fellows :}
 
user3079266
6:46 AM
helloc all; //good morning ;)
 
7:37 AM
helloc all;
 
user3079266
helloc @PeterVaro; //sup?
 
helloc @Lundin; // very long time no see
howdy?
@Mints97 I'm okay, thanks, drinking my coffee, reading the news
the usual daily routine :P how's yourself?
 
user3079266
I'm still struggling with my code... Just to think of it: I wrote every part of it with the exception of one file in clear and easily understandable code, split into functions that perform only one specific action... and this one goddamn file, two functions, 190 LOC, written in the middle of the night and not touched afterwards because it seemed to work... I've captured at least 6 memory leaks in it already, and I suspect there is more...
 
user3079266
now I seriously consider rewriting the entire file from scratch... it may actually get me working code faster than more bug-hunting
 
@PeterVaro Hey there.
 
7:45 AM
@Mints97 sometimes pressing that big-red-reset-button helps. I'm a huge fan of starting things all over!
@Lundin 'sup? where were you these days? what are you working on?
 
190 LOC isn't a big deal to rewrite. But of course that depends on how complex the code is.
 
user3079266
@PeterVaro I just need to get the code working ASAP... goddamit... I really am going to rewrite it now...
 
@PeterVaro Been working hard :) Right now I'm trouble-shooting electronics actually. Not exactly my forte. Just managed to burn circuit board... ah, the smell.
 
user3079266
@Lundin it's a part fo code that makes several operations with text and uses dynamic allocation. malloc, realloc and free all over the code... weeh...
 
@Lundin also 190 LoC in CommonLisp is totally different than 190 LoC in C :P
@Lundin sweet-sweet hw ;) I always wanted to create my own circuit board..
I mean, I did with bread-board and stuff
but to actually create my really own, final printed version..
that's a totally different thing :)
 
7:52 AM
My company does that all the time. It is really cheaper (for the company) to order real PCBs and have them assembled by professionals, than to mess around with hand-soldering and lab wires. Because you save yourself so much time when it comes to trouble-shooting.
 
makes sense
although I "invented" a technique for bread-boards to make them just as nice, "hard" and safety as they were soldered
 
But of course, if the layout is screwed up, you're in trouble, like I am now, heh... The guy who did this PCB is no longer in the company and none has tested his last board since he quit. I did this morning, and the power supply got some hiccups...
 
I created my own wires, which are way harder, then the ones you can buy in the store -- you know, I'm a jewellery designer, so I know how to do these things ;) -- and bend them as they were flat circuits on the board
the result looks nice, and it is very durable
@Lundin ...aaaaaaand there is no one to blame ;)
 
user3079266
wow, that's so interesting O_o I never had any exposure to electronics...
 
@Mints97 actually that IS part of the magic!
imagine: you can build something and control it with your code
how cool is that?
 
user3079266
8:00 AM
@PeterVaro I know... but the electrical engineering that is involved in even microcontroller creation is, I believe, extremely sophisticated and nearly impossible to create with regular tools. Or am I wrong?
 
you can't create micro-chips at home, you are right about that
but tbh I wasn't talking about designing and creating a microchip as the fun part
for me a pre-made board (Arduino, RPi, PyBoard) connected to me own one is more than enough excitement!
@Mints97 I was wrong:
 
user3079266
@PeterVaro whooooah! O_o
 
Well i think we just found the problem :) afk
 
@PeterVaro You mean xkcd.com/1411 ? xP
@Lundin aaah... so cool. I wish we'd come to this point faster...
@PeterVaro motherf$Ł*(@, Flash player, why?!
 
@Kamiccolo if you paste the xkcd URL without any other message:
it will be automatically recognised, just as wikipedia, youtube or other SE links
 
user3079266
8:13 AM
@Kamiccolo huh? YT supports non-flash video displaying.
 
^ still the coverage is not 100%
 
user3079266
and what is wrong with Flash, anyway? I think it's a great web plugin (if you don't consider its security holes)
 
there are videos which are only available in Flash
 
@Mints97 Yup, BUT... this feature still highly depends on in which format it was uploaded.
 
user3079266
@PeterVaro that one plays in HTML5 for me
 
8:14 AM
actually for me too ;P
 
@PeterVaro if You upload WMV, for example, it always does that xd
 
what browser?
 
user3079266
@Kamiccolo WMV? someone still uses that? O_o
 
@Lundin what was it?
@Mints97 :D:D
 
@Mints97 oh yeah. Flash is another thing still amazes me every single freaking time.
@PeterVaro oooohhhh! Thank You very much!
 
8:17 AM
Flash was actually pretty cool back in the days when it was Macromedia and not Adobe
both the editor itself, the format, the ActionScript, the capabilities
but after Adobe bought it, literally nothing has changed
although 10 years (at least) passed by
 
@PeterVaro yup, no wonder we had sooo many more or less nice games and stuff build with it,
 
The so-called "professionals" who have mounted the circuit board had put a 7.5V transient protection zener on the 24V supply, instead of one rated 32V...
So this diode will heat up until it melts, pretty much
 
@Lundin aaah... also fun. So, device was build with intention not using it too long and too often xD
 
user3079266
@PeterVaro no, you're wrong. They released a cool new standard of AS (3.0), created a great editor that I really enjoyed using, added wonderful 3D support... and yeah, broke backward compatiblity a bit, but these morons can't do a single thing without that, so it's understandable...
 
Actually, the component marking looks ok. Hmm...
 
8:21 AM
@Mints97 that 3D support is nothing but an absolute shite
I hated using it, every single time I had to
AS 3.0 -- I don't know, I never had to use it, so it could be nice, I can't judge
 
user3079266
@PeterVaro I wouldn't say that, I've seen awesome games created with it, and, being Flash, it doesn't put as heavy a toll on the browser as other 3D plugins like Unity3D
 
the editor => still the same as it was when it was Flash MX
 
@Mints97 and closed official Linux support.
 
@Kamiccolo wow, I did not know they had one!
 
@PeterVaro ah xD
 
user3079266
8:24 AM
@Kamiccolo yeah, well, that was after Apple kicked them out of iOS. They basically killed their entire flash mobile support then, and Linux sort of went along with it, if I understand the situation correctly.
 
if anything, that was an awesome decision from Steve Jobs
Flash had to die -- it was only a matter of time
 
@PeterVaro but it's still doesn't. Another bugging thing after Flash --- ActiveX in "open" government projects.
 
@Mints97 btw a lot of my friends who used Flash to create games, and now uses Unity says it is awesome
 
user3079266
anyway, whatever people say about Flash, I still say it's a great thing. It lets you create cool games easily by using a nice OOP language, it works and loads fast and is lightweight, both in a browser and on desktop, has great backwards compatibility, and works everywhere for Windows.
 
which is not a big surprise => the same team created it who were in the original macromedia team
which company was AWESOME
 
user3079266
8:27 AM
@PeterVaro I am learning Unity now. it sure is cool, but much slower than Flash.
 
@Mints97 I don't know that.. I've never used Unity myself
@Lundin ouch.
 
Wow, 700 messages
 
helloc @mantal;
we are on fire ;)
 
user3079266
Also, I love Flash because I started learning programming by hacking others' flash games... I still have a great collection of tools for this purpose, and I can still backup any online flash game, however complicated its structure (except for those that use super-complicated webservices) to offline and make it work both in a browser and on desktop.
 
aah... I'm in love... again. Such a nice voice. Check out the bio: http://en.wikipedia.org/wiki/Jeri_Ellsworth
:}
 
8:29 AM
helloc @PeterVaro, I see that x)
 
@Kamiccolo she is the love of all the nerds out there ;)
helloc @BartekBanachewicz;
 
user3079266
helloc @BartekBanachewicz;
 
@Mints97 hiiiii<yaawn>iii
 
helloc @BartekBanachewicz
 
so many funny teal things at my screen
I just got to work, I'm barely awake :P
 
8:36 AM
helloc @DhirajThakur;
 
user3079266
@PeterVaro dammit, and I'm dating a girl just as described in the article... some of these points look familiar ><
 
Hmm okay seems I won't be able to do any work today... I was trouble-shooting this damn thing by using a thermal camera. It pointed to a zener diode, but when I removed that component, the heat moved to the actual regulator instead. So... this problem is beyond my electronic knowledge.
 
@Mints97 ikr? (although I haven't met any woman in the last x years who wasn't make me bored at some point)
at some point == really short time
 
Very few women in the programming profession :) Which is odd really... when I studied computer engineering, at least a 3rd of the class were women.
Wonder where went after finishing studies...
 
I'm not looking for a developer-ess ;)
I'm looking for smart-enough partners -- that's a different thing
 
user3079266
8:47 AM
@PeterVaro yeah, me neither :D imagine taking a girl to a date and talking about programming all the time. It would get boring quickly XD
 
Well, that's true. I avoid programming in my free time, I don't go near it.
 
@Mints97 especially if she were obsessed with Haskell :D:D:D
 
lol, we're mocking our designer
 
@Lundin why?
 
> come on stop drawing and do some work already!
 
8:49 AM
Because I already do programming 8 hours per day
 
@BartekBanachewicz you mean our Designer, or your designer at your company
 
@Mints97 just as any other subject :V
@PeterVaro the latter
 
@BartekBanachewicz huh -- okay then ;)
 
If you share interest in programming, I don't see why it should get boring
 
@Lundin so you don't have not-work related projects at all?
@BartekBanachewicz talking 24/7 about programming is still boring, you have to admit that
 
8:50 AM
None. I used to do that 10 years ago, writing some small computer games and things like that.
 
@PeterVaro dunno, I can go for pretty long tbh. It's such a diverse topic
 
maybe you realised something we have to release later.. probably you are wiser than us? ;)
@BartekBanachewicz I'm aware of that ;) Anyway, I still like to talk about plenty of things
my mind is full of interesting topics (at least interesting for me)
which are not related to programming at all
 
For me to do programming in my free time, it would have to be a very interesting project. Not just something you do for programming's own sake.
 
fair enough
 
user3079266
I can't program anything for "programming's own sake" no matter how hard I try ;P
 
8:54 AM
@Mints97 than what will you do, when you are going to be in a job, where you are going to have a specific task, which is absolutely not interesting at all -- but someone has to do it?
 
user3079266
@PeterVaro meh, that would be programming for my own sake - to keep the job! XD
 
oh I see -- tricky logic ;)
 
damn, I introduced another informal contract in my code :S
 
A lot of programmers work with rather boring things, where the programming in itself is the motivation, not the result/product. Things like database design for example... nobody would do that because they find databases fun and exciting.
 
@Lundin I disagree.
 
user3079266
8:57 AM
@Lundin people would do that to make their application work faster and more efficiently, and to make database requests more easy to understand. It all comes down to a project that needs to be done or improved/refactored.
 
database requests should be made in EDSLs imho
or via ORM
 
@Mints97 Indeed, and then you do it because you have to. Not because it is fun.
 
@Lundin the fact it's not fun for you doesn't mean it's not fun for someone else
like coding in C is akin to hitting your leg repeatedly with a heavy object
 
@Lundin The fun is to change something ugly to something awesome
 
I know it sounds improbable, I know, but there are wicked people on this planet that like C.
 
user3079266
8:59 AM
@Lundin for me, working on a project may not be fun, but I take great pleasure whenever I complete one, so it's still worth it =)
 
and thank god for that, because that means we, high level master race, don't have to write in it.
 
I wouldn't say that I like C, for any other reason than I can write it in my sleep. The reason I'm using it is rather because there are no other sane alternatives.
 
Rust! :)
 
user3079266
@BartekBanachewicz whenever you say "high-level master race", I can't help but remember this: youtube.com/watch?v=mzaYiMciIMY
 
@Mints97 think more 5th Element
 
9:04 AM
I work with embedded systems, so there are really no alternatives... Assembler is too low-level and non-portable, Ada has no tool support, and C++ is too flawed and too complex.
 
@Lundin you don't have to use every single feature of C++ you know
Also I don't think that C++ is really more flawed than C, in the sense that if it has more flaws, it's just because it's bigger
 
user3079266
@BartekBanachewicz bloated would be a better term, no? ;)
 
@Mints97 No?
Why do you think it's bloated?
 
@BartekBanachewicz The problem is that if there is a language feature available, sooner or later some moron will use it. It's the Murphy's Law of programming really. Even if you do reduce C++ to something more bare bone like "C with classes", you still have far more poorly-defined behavior remaining, than you have in C. Also, you have reduced the language to a point where you might as well be writing C instead.
 
user3079266
@BartekBanachewicz I just don't know where the distinction between "big" and "bloated" lies =)
 
9:09 AM
@Lundin no, it's really not "as well be writing C"
Introduce coding guidelines and code reviews
Educated people and promote high coding standards
But don't blame the fact that people are retarded on a language that's trying really hard to fix the mess that C is.
@Mints97 "bloated" means "unnecessarily big". I wonder what's unnecessary in your opinion.
@Lundin Even if you're using strict C subset of C++, it's still better to use it if you can.
 
user3079266
@BartekBanachewicz why exactly? how is it different from C?
 
@Mints97 it's a bit safer.
 
\OFF
Made my day: (so many childhood memories)
http://coub.com/view/3cddb
\ON
 
well okay, if you want to use designated initializers, C++ doesn't have them unfortunately :(
 
There was this thing called Embedded C++ en.wikipedia.org/wiki/Embedded_C%2B%2B which was actually a good attempt to make a useful subset of C++.
 
user3079266
9:12 AM
@BartekBanachewicz why and how is it safer?
 
@Lundin no, that was freaking terrible
it was absolutely and absurdly awfully bad and terribly awful
@Lundin how much have you been writing in C++?
 
@BartekBanachewicz Why? They removed all the things you wouldn't want to use in embedded systems.
@BartekBanachewicz I've worked in C++ to and fro for the past 12 years or so
 
@Lundin they made arbitrary decisions that made the language absolute crap
FYI embedded systems have RAM of hundreds of MBs and CPUs of GHz
thank god this idea died in fire like it should.
 
Well the only time I actually used C++ in embedded was with a compiler that used Embedded C++. That was in.. 2003 or something. It worked out fine.
 
@Mints97 it has a stricter type system
 
9:15 AM
@PeterVaro appearently You've never met a female Lua developer xD Me neither. But those are truely mythical creatures xDDD
 
@Lundin that was 11 years ago.
Let me repeat
 
Err, no embedded systems do not have that much RAM or MHz... you are thinking about... a PC.
 
@Lundin Welcome, traveler from the past!
You see, we now have water closets and electricity at our homes
 
@Kamiccolo they are so mythical, that they don't even exist ;)
 
Also our mobile phones and fridges have multicore CPUs
 
9:17 AM
@BartekBanachewicz You have never worked with embedded systems, have you? A smart phone is not an embedded system... it's a portable PC.
 
yay more arbitrary divisions
 
I know what a PIC is TYVM
 
@PeterVaro people around keeps telling that programmers are so versatile... having some knowledge and what to say almost about everything: from parenting, to black holes. From ordinary bladder size and it's expansion capabilities to second wife of Benitto Musolini or how to control the mother board with a metal fork.
 
lol FFS just because I code in Haskell you don't have to assume I have no idea on embedded systems
 
9:18 AM
@PeterVaro heh, You've got my point xD
 
@Lundin I have. And there are bigger ones and smaller ones.
 
The CPU I'm currently working with is brand new, a 32 bit Power PC core for automotive ECUs. I get 120MHz clock and 1Mb RAM. And that's a lot :)
 
Seriously, you've been coding in C++ for 12 years.
And you think that the idea that removed namespaces from the language was good?
 
Yes, but not not C++ for embedded systems :)
 
You must write really shitty C++.
 
9:19 AM
@Lundin eLua all the way for this!
 
Not even mentioning the fact that templates are hellishly useful for codegen on embedded platforms
and they can (which I've even proven once here) produce smaller binary than handwritten C
 
I'm not arguing for or against EC++, I've used it once and it worked for that project, a 16 bit real time system with very limited resource. If you ask me about details in that EC++ standard, I wouldn't know a thing about it.
 
@BartekBanachewicz meh. But debugging those...
 
@Lundin I would probably recommend you, to stop arguing, because FYI BartekBanachewicz is a Haskell believer, and nothing, I repeat: NOTHING can be good enough for him, only his beloved language -- so it is quite pointless to convince him -- I guess we all give up on him in this room.. maybe not @DrorK., but he will do the same at some point ;)
 
@Kamiccolo debugging what
 
9:22 AM
I said so many times, don't use this language
(I kicked-muted him for 1 minute)
 
Why did you kicked him ?
 
Seems to be rather immature...
 
because I told him for 3 months, not to use those words
 
@Lundin as immature as calling me out on the fact that I like Haskell in the middle of C++ discussion
 
9:23 AM
or at least give it a strike-through or something
 
I'm sorry, I have a really short temper on stupidity.
@Lundin well, those aren't even details :) those are all on the wiki page
 
user3079266
now, guys, no insults!
 
@BartekBanachewicz No, because you don't seem able to have a civilized discussion with a random stranger without hurling insults.
 
Embedded C++ is a proper subset of C++. The following language features have been removed:
Multiple inheritance
Virtual base classes
Run-time type information (typeid)
New style casts (static_cast, dynamic_cast, reinterpret_cast and const_cast)
The mutable type qualifier
Namespaces
Exceptions
Templates
 
@Mints97 thank you ;)
 
user3079266
9:24 AM
@BartekBanachewicz so it's basically C with classes? =)
 
@Lundin more like, I was really amazed how you could find lack of those not disturbing
@Mints97 I have no idea what this is really
neither had the authors of it, apparently.
 
If I were to do an embedded C++ project now, I'd probably look into MISRA-C++ instead. But I know nothing about that standard either, I only know that MISRA-C is the best thing that has happened to C since C99.
 
And one thing I can tell you however, is that no professional uses PIC. It's a core from the 1970s... the only reasons you would ever use anything from Microchip is because you need to be backwards compatible, or because you've been living under a rock since ARM was introduced in the 90s.
 
> s a set of software development guidelines
 
9:26 AM
1 message moved to Trash can
 
@Lundin I know, right. I've programmed them in their funny assembly.
I think they would struggle even with a bread toster.
 
The PIC core is just pure awful... at least the 8 bit one
 
fully agree.
I bought myself an STM32F4 recently
considering how cheap they are, the difference in power/possibilities is tremendous
 
That's a cortex m4 right?
 
@Lundin yep
 
9:29 AM
We were considering ST for a previous project but went for NXP, because of some nice CAN bus features.
 
do you manufacture your products in larger quantities? I never really looked into that aspect, I have to admit I am mostly a hobby embedded programmer :)
 
Not huge quantities... maybe 1000 circuit boards per year for the high runner products.
 
Oh and regarding PIC and NXP, gotta love this: nxp.com/products/microcontrollers/cortex_m0_m0/lpc800
The PIC killer. This part crushed the last reason why you'd ever want to use PIC. And that was because hobbists love through-hole DIP 8 packages
Why use a PIC if you can get a 32-bit Cortex M0+ for less than $1.
I can see why hobbists don't want a 48-pin surface mounted QFP :) But they can buy this one in a DIP8 package and mount to their horrible breadboards ;)
 
9:36 AM
@Kamiccolo to the margin of the girly-topic:
 
@PeterVaro I was expecting something "Kill'em'all like" xD
 
admit it, this better than that ;)
 
sigh parse error pointing to the end of the file
I swear there was a flag that showed where it starts
 
@PeterVaro kind a NFWS xD guy keeps zipping/unzipping his pants and belt.
 
@Kamiccolo lol
 
9:45 AM
from Your disliked era xD
 
will check it in a mo'
 
10:00 AM
BTW @Lundin I'm starting to like this MISRA thing; they suggest avoiding malloc :D
 
MISRA is somewhat radical... they ban a lot of things, like the whole stdio.h. But essentially they just aim to get rid of bugs
It has become de facto standard everywhere in the embedded industry, or at least MISRA-C:2004. There's a newer version from 2012 which allows C99, it is a bit better.
 
@Kamiccolo those terrible drum sounds, yeah ;)
 
@Lundin niiiice
 
although I still appreciate the void of the singer
 
banning stdio.h and malloc would be the first things I would do in C too
 
10:06 AM
@BartekBanachewicz They also ban goto, continue, more than 1 break inside a loop, only 1 return from a function etc etc. Lots of restrictions about function-like macros too.
The big thing is enforcing various casts to get rid of all bugs related to implicit type promotions though. Very few C programmers actually know how the implicit type promotion rules work in C...
 
*void = voice
 
@Lundin uh okay one return from a function is pretty bad
 
it is just as bad as removing gotos from a language which only support explicit error checking
 
@BartekBanachewicz I think so too, I've made deviations from that rule. Because there are cases where multiple returns actually make the function -more- readable.
 
helloc @Inisheer; // wb
 
10:10 AM
@PeterVaro Hey Peter, all
 
@BartekBanachewicz MISRA just inherited that rule from a safety standard for industrial applications, which in turn cite some book by Edward Yourdon written in the 70s...
and thats the only rationale they have for that rule
 
eh C world is really outdated at places
 
user3079266
helloc @Inisheer;
 
hey Mints
 
The intention was to prevent spaghetti code I suppose. But if you are writing a function with extensive error checking, like a parser, you will want to return an error code as soon as you find an error.
The alternative is to write some brace mess like if(!this_error) { if(!that_error) { if(!something_else...
 
10:12 AM
Oh I'm not very fond of non-declarative parsers :S
I think they are terrible to maintain
 
@Lundin that is a just terrible.. K&R made a terrific job on flow-control, why would anyone wants to limit that?
 
@PeterVaro I guess it's safe to presume a drum machine :}
 
it won't make the code safer -- only the language simpler and the code more complex and harder to maintain
@Kamiccolo I thought about that, yes -- and most probably a cheap synth-drum :(
(which wasn't cheap back then, but the sound itself is cheap)
 
@Lundin uh. Agree with one exit point rule. But not with removal of goto :(
 
Generally, you want to avoid non-conditional branches as those can be used to create spaghetti. Essentially goto, continue, multiple breaks, return from function are all the same thing.
goto can actually be 100% replaced by return for all cases where you would want to use goto.
 
10:19 AM
yes they are -- but strictly removing those makes your own life harder
@Lundin not necessarily
think about a complex error handling situation or the break out of a nested loop
 
MISRA-C originally aimed just for safety-critical applications, why they want to remove potential hazards. But nowadays it is used in most embedded systems.
@PeterVaro Yes those are the only 2 valid cases where you can use goto. And in both of those cases, a return is much more readable, at least in my opinion.
 
@Lundin one sec, I create a very small example, I'm very excited to see how could you make that more readable with using only returns
 
@Lundin and vice versa. Multiple returns can be replaced by couple of gotos and proper infrastructure of releasing resources.
 
It all boils down to goto being superfluous, with a great potential for writing spaghetti code if abused. Another reason to avoid goto is to avoid the goto-considered-harmful debate :)
@PeterVaro Well I just ordered food so I gotta go for a while. Be back in an hour or so.
 
@Lundin eh, C is really really limited when it comes to error handling
I'd say it actually doesn't have any reasonable mechanism for error handling
And at the same time doesn't allow creation of one.
That's one of the reasons C code crashes (or malfunctions) so often - inability to express runtime failure in a reasonable way
@Kamiccolo "proper" :P
 
10:27 AM
@BartekBanachewicz That may because I'm not experienced but when I see no difference between let's say java nullPointerException and a segfault
 
@mantal there's more than one difference
Also, I am not sure if java is the best example here.
 
sigh just accidently deleted code sample of my point. By I've already wrote something like it here.
 
"null pointer" exception stems from implicit nullability
 
@BartekBanachewicz Mr.
 
which I ultimately think is a bad decision
Also, java can produce way more descriptive exceptions that just that, whereas segfault is just "something [DANGER SWEAR WORD]---fcked--- up"
 
10:30 AM
@Lundin so how would you solve this with only using returns (and actually one return) in a way that it would be more readable:
static bool
function(T1 **t)
{
    T1 *t1 = malloc(sizeof(T1));
    if (!t1)
        goto Exception_From_T1_Alloc;

    /* Do something with t1 */

    T2 *t2 = malloc(sizeof(T2));
    if (!t2)
        goto Exception_From_T2_Alloc;

    /* Do something with t2 */
    t1->m1 = t2;

    T3 *t3 = malloc(sizeof(T3));
    if (!t3)
        goto Exception_From_T3_Alloc;

    /* Do something with t3 */
    t1->m2 = t3;

    /* If all goes well */
    *t = t1;
    return true;

    /* If somethign went wrong */
 
Jul 14 at 17:28, by Kamiccolo
:17692119 loops everywhere?
Even in such code sample:

int some_function(char *buffer, char *another_buffer)
{
    int retval = 0;

    if (buffer == NULL)
    {
        DEBUG("Buffer is NULL!);
        goto done;
    }

    if (another_buffer == NULL)
    {
        DEBUG("Another buffer is NULL!"):
        goto done;
    }

    //do stuff

    retval = 1;

done:
    if (retval = 0)
    {
        // free allocated resoources here!
    }
    return retval;
}
For example/
 
walls of code
walls of code everywhere
 
@BartekBanachewicz it is okay to use it like that
 
@BartekBanachewicz Gdb tell me where is the segfault, like java does.
 
Only difference, my code having only one exit point and only one label, no more, per function.
 
10:32 AM
@mantal and yet still C is much harder to debug
also, again, java is not the best example imho
 
What would be better exemple ?
 
C++ maybe.
because it doesn't have a GC.
in C++ throwing an exception implies deallocating memory and freeing up resources
hm, lemme find that example I've shown to @Mints97
17 hours ago, by Bartek Banachewicz
// C variant
void fn () {
    int* arr = malloc (sizeof(int) * 10);
    stuff(arr);
    free (arr); // forget that and you're dead
}

// C++ version
void foo() {
    std::vector<int> arr(10);
    stuff(arr);
} // arr is automatically deleted when its scope ends
In C++ if you throw between stuff and construction, arr is still automatically deleted
Also, if creation of arr fails, all other resources are also deleted.
@mantal it ultimately does the same that C equivalent, but in a much shorter, cleaner and safer way ^
 
I see
 
Yep, so you can return from anywhere and you don't have to worry about deallocation.
hm, actually.
hey, it works! :D
#include <stdio.h>
#include <stdlib.h>

#define WITH_ALLOC(T,X,FN) \
    T* X = malloc(sizeof(X)); \
    FN \
    free(X);


int main() {
    WITH_ALLOC(int, x, {
        *x = 5;
        printf("%d", *x);
    })
}
 
I don't know what it is but is is ugly :x
 
10:46 AM
@BartekBanachewicz that just looks terrible..
 
@PeterVaro why?
 
omg.. my eyes are bleeding..
 
@mantal I know, faking RAII in C doesn't work very well
I was just curious, is all.
 
@BartekBanachewicz because it is you who are always concerned about safety -- yet using macros the most unsafe ways possible
 
@PeterVaro is it?
tell me about it.
 
10:47 AM
it is.
btw: sizeof(T) I guess you meant that
 
@PeterVaro amounts to the same here I suppose.
 
which is one example of this very unsafe stuff you did
 
@PeterVaro can you tell me what exactly is unsafe here?
 
everything?
 
That's not very descriptive.
What would you say if I, asked "what in C is unsafe", said "everything"?
 
10:50 AM
I'm actually into something right now, I will write it for you in a safe way after I'm done
how 'bout that?
 
user3079266
@BartekBanachewicz hah, that's some inventive thinking :D
 
@PeterVaro I'd rather know what's so particularly bad in my example, but, sure, I don't mind the wait
> warning: ISO C forbids nested functions
whaaa :(
 
user3079266
@BartekBanachewicz that's basically what's bad about your example ;)
 
@Mints97 nah, I just added that fragment
#define WITH_ALLOC(T,X,FN) \
    T* X = malloc(sizeof(X)); \
    int fn() { \
        FN \
        return SUCCESS; \
    } \
    fn (); \
    free(X);


int main() {
    WITH_ALLOC(int, x, {
        *x = 5;

        if (*x == 5)
            return ERROR;

        printf("%d", *x);
    })
}
:D
if nested functions were allowed, I'd create a function called fn##__FILE__##__LINE__
this example works, btw.
 

« first day (116 days earlier)      last day (3528 days later) »