« first day (368 days earlier)      last day (4562 days later) » 

@GlenP A C# feature. You can basically add your own methods to any class/interface you want. It's only syntactic sugar but still.
 
well interefaces arent really a problem they are just annoying :)
oh cool
 
@RMartinhoFernandes can you please show small example imitating this sentence "If the name isn't qualified it never refers to a template instance"
 
i like C#
this lanuage scala was better but it doesnt run on .net
 
Extension methods are just a way of turning SomeStaticClass.Foo(x) into x.Foo().
 
8:01 PM
oh i get it
 
I have a couple of functions that toggle "raw" terminal input: MakeRaw() and Reset(). This introduces global state, obviously. Precautions must be taken to make sure MakeRaw() isn't called twice in a row, so it can't Reset() to raw mode. I have done this, and it works fine. Someone suggested I use a more object-oriented approach, but I don't think that makes sense in this case.
The functions can only ever act on one terminal - the terminal. It doesn't make sense to instantiate a ModifiableTerminal object and pass it around. In fact, even if I did make such a class, there would still be global state so different ModifiableTerminal objects couldn't step on each other's toes. Does my design rationale hold water?
 
ive been reading some about these function mmlanuages they are pretty cool
 
@MrAnubis There's an example in the book, right after that text.
I can clear your doubts about it, but any example I can craft will look practically the same.
@GlenP You know Haskell?
 
nope but i was checking out lisp and this Java like one called Scala
i think scala might hit the big time in Java land
its a total OO functional hybrid
 
@RMartinhoFernandes in the example , there is only one friend multiply(int) {} unqualified name , which doesn't imitates the line "If the name isn't qualified it never refers to a template instance"
@RMartinhoFernandes please show the example?
 
8:06 PM
the coolest feature is all operators are functions/methods and vis versa
its like operator overlaoding on steriods
 
@MrAnubis That friend multiply(int) {} isn't qualified (it doesn't have any ::).
So, according to the rules it cannot refer to a template instance.
 
antoehr cool feaute is there are no statements only expressions
but its still readable-- its really cleaver
 
@GlenP Isn't "total hybrid" a bit of an oxymoron?
 
It will not refer to`void multiply<int>(int);` .
 
a bit :)
 
8:07 PM
Fuck you Markdown.
5
That friend multiply(int) {} is the example.
 
@GlenP Hmm, all-operators-as-methods sounds a little dangerous.
 
Who the heck pinned that?
 
I don't want library writers reinventing the language.
 
friend ::multiply(int); is qualified, so it refers to the template declared before.
 
well of course you could make a crazy mess-- but dangerous nah
 
8:09 PM
friend multiply(int); isn't qualified, so it doesn't refer to any template. It declares a new non-template function.
 
sbi
@RMartinhoFernandes Whistles.
 
@RMartinhoFernandes thanks a lot!
 
so 4 + 5 can be rewriten as integer(4).+(integer(5))
so its the "+" method of class itneger
neat huh
 
@RMartinhoFernandes but isn't the declaration is wrong , missing return type, should be friend void multiply(int) {}
 
@MrAnubis Oh, you're right, sorry about that :)
 
8:10 PM
@GlenP honestly, I don't see why. In particular, why does everything have to be member methods?
 
@GlenP So literals - and by extension, primitive types - are classes?
Therefore, one could theoretically inherit from int?
 
I doubt it.
 
yes primative types map to classes
 
The JVM hurts you.
 
but plenty of languages define primitive types to be classes, that's not too unusual
 
8:11 PM
@GlenP I'm not sure how I feel about that.
 
no it autmoatically converts to normal math
 
Unless they use java.lang.Integer every-freaking-where.
 
it still has real interegers it just autmatically kow when to use a primative or the class
 
@RMartinhoFernandes presumably the compiler can optimize it by turning it into regular ints wherever possible
 
its rewrites it into bytecode for you if needed
 
8:12 PM
@Maxpm And the "int class" is final.
 
this is scala not java
 
@RMartinhoFernandes Hmm.
 
btw, thanks to @FredOverflow posting that Javascript video the other day, I now want to poke around with JS...
 
so i was saying:
 
Thanks a lot... It's hard enough finding time for working on my library without people giving me the javascript itch
 
8:13 PM
I think I'll stick to the way C++ handles it: if you never want to touch an object, you don't have to.
 
@sbi you also use linux?
 
"farmer milk cow"; can be written as farmer.milk(cow)
its not goign to mess up all your math
if you write 4+5 its not goign to tough any object
 
@GlenP well yeah, that's how you'd write it in Java too
 
no no "farmer milk cow" thats the code--- milk is a operator
 
@GlenP Wait, aren't ints objects in Scala?
 
sbi
8:15 PM
@MrAnubis In my last job I had to use Linux once in a while to make my code compile. Usually I used a VM, though. Before that, I used to port stuff to MacOS, too. (For years I had a PC and a Mac under my desk.) Now I'm doing .NET stuff, so nothing but Windows.
 
they are both
 
or, it'd probably be FarmerFactorySingleton.getInstance().getFarmerFactory().createFarmer().andSoOn..‌​.
 
they are both it know what you want
 
@jalf Your lack of abstraction confuses me.
 
its not goign to create to obejects just to do some addition
 
8:16 PM
No, the application would be an XML ruleset engine, and the farmer, cows and milking would be written in 30MB of XML schemas and configuration.
 
@RMartinhoFernandes it's pretty much the same in .NET. If you write 2+2, it uses plain ints, but if you write 2.Tostring() you call a method on the Int32 class
iirc, anyway
 
That way, you can write anything!
 
@GlenP I expect it to create an object (a Scala object) for the value 9.
 
yes you can write anything :)
it wont create an obeject unless you call a method than it will
 
Meh, non-object types in a OO language are weird.
 
8:17 PM
the thing that interests me about scala is that they use STM :)
 
@GlenP So Scala doesn't call ints objects (I don't care about JVM objects, I'm asking about the language here)?
 
so if you write 5.tostring() scala is going to call the static method of the INteger class
 
you can keep the rest of the language ;)
@RMartinhoFernandes I think the point is that conceptually, all ints are objects. But the compiler might optimize it by turning them into, well, ints where possible
 
@sbi scary linux for me , though time teaches everything :)
 
8:18 PM
Scala has full OO for integers BUT it will also use primatives when it makes sense-- ok?
its treates them special it does some autmomatic conversions between OO and primatives for you
 
anyone want to commit to this proposal ?:
222
3D Graphics, Modeling & Applications

Proposed Q&A site for 3D graphics creators.

Currently in commitment.

 
this featute is called autoboxing-- alot of laguanges have it now
 
I looked it up. Scala calls ints objects.
That's what I wanted to know, I don't care about the implementation.
(C# doesn't call ints objects even though they can be treated in a similar manner.)
 
ok im just trying to help :)
its you have good autoboxing you really have the best of both worlds you see
i mean i dont personally think its a big deal but they wanted everything to be an object
 
Like Ruby?
 
8:22 PM
liek a lot of lagaunes
i dont know ruby
so all types are objects
 
I don't know many languages that take the "everything is an object" mantra as far as Ruby.
 
all operators are functions
 
They are incredibly obsessed with it.
 
Everything is an object, but good luck with passing functions around.
 
You have four different kinds of them!
 
8:25 PM
there is a Function object!
 
I prefer Python model, thank you very much.
 
scala is functional you can do just about anything with functions
remember this cow said its a hybrid :)
 
C++ is also a hybrid. Look how it ended up.
 
Big deal. C++ has a bit of functional idioms as well.
And Python.
 
sbi
> As many as 51 wild animals, including cheetahs, grizzly bears, black bears, wolves, lions, a white Siberian tiger, camels and giraffes were running free in Zanesville, OH, Tuesday night, which has a population of about 25,000 residents. - abcnews.go.com/US/story?id=14767017
 
8:28 PM
Next C++ big feature: vector comprehensions. I called it first.
 
I doubt it.
 
(I'd say modules, but bahaha, fat chance.)
 
why my random number generator is not working? ideone.com/zwMSN
 
Scalas really a diff kindof lanuage than c++ no in competiion
 
Every language is a different kind of language than C++.
 
i got to try to get some work done cya cows later
 
I eat cows. I'm not a cow. I'd be a cannibal if I were a cow.
 
Cownibal.
 
@MrAnubis I'm guessing GCC doesn't have it implemented yet.
 
sbi
8:33 PM
 
Also uniform_int_distribution produces integers.
 
sbi
In other news, Microsoft is re-writing their C# and VB compilers - in C# and (make sure there's a chair in the vicinity to sit down before you read on): VB.
 
@RMartinhoFernandes aah , that was the mistake , thanks again:)
 
@sbi They started that a long time ago.
Before 4.0 was released even.
 
sbi
@RMartinhoFernandes Honestly, I can see that C# is up to the task, the language being easy enough to parse that a few percent slower compilation doesn't matter. But writing a compiler in VB?
 
8:38 PM
VB.NET is a lot like C# in a verbose dress.
Don't be fooled by appearances.
 
sbi
@RMartinhoFernandes I use my keyboard. Usually.
 
It makes sense to write a compiler in a language you're most familiar with, i.e. the one you're writing compiler for.
 
The last version of VB has automatic deduction of line continuations, and that's the single most complex syntactic feature of VB you won't find in C# (because lines don't matter in C#).
 
sbi
@CatPlusPlus I know that theory. Still. Would you write a Logo compiler in Logo?
 
Dunno. If it were shorter and easier to maintain than in e.g. C++, maybe.
I don't know Logo.
 
8:44 PM
Well, I know VB.NET and C# and they're pretty similar.
So similar that they decided to just evolve the two languages as one.
 
9:12 PM
Abraham Linksys is my favorite.
 
look at the second item on that list :P
 
9:24 PM
I noticed.
 
Which one should I use for general purpose if something goes wrong, std::runtime_error or std::cerr ?
 
What does it mean for something to go wrong?
 
They're not the same thing.
Well, unless you want to throw streams around.
Then don't.
 
9:50 PM
Quiz time: Can you judge by the naked eye whether this code will work? It's small refcounted memory buffer class.
 
Rule of three.
 
I think all three are there.
 
It is actually.
 
is there a "c" forum?
 
@Questioneer you can ask a question on SO using the "c" tag.
 
9:52 PM
Ain't this nasty? std::swap(rc, rhs.rc);
 
i can ask here as long as i tag it c?
 
Yep.
And if it
is a decent question.
 
buffer a(10); buffer b(20); buffer a2(a); b = a;
 
how do i tag it "c" here?
 
Why can't he ask it here? C++ is a descendant of C. Don't tell me you all hate C that much
 
9:54 PM
@Questioneer You'll find when you are finished typing your post. If you don't tag it
 
Oh you take the argument by value.
 
someone else will do it for you.
@LewsTherin I don't care.
@LewsTherin AFAIK he was asking for a "C" forum. So I helped him with that.
 
unsigned int size = fseek(pFile,0,SEEK_END);
fseek(pFile,0,SEEK_SET);

while (size>sizeof zeros)
size -= fwrite(&address, 1, sizeof zeros, pFile);
while (size)
size -= fwrite(&address, 1, size, pFile);

is my current implementation of a clear function. I want to call this function and clear a file and set the file equal to all zeros. (this code isn't complete yet)
 
@StackedCrooked yeah...
 
clear(unsigned long long address, unsigned long long nbytes)
{ unsigned char zeros[# of zeros not sure what goes here also];

unsigned int size = fseek(pFile,0,SEEK_END);
fseek(pFile,0,SEEK_SET);

while (size>sizeof zeros)
size -= fwrite(&address, 1, sizeof zeros, pFile);
while (size)
size -= fwrite(&address, 1, size, pFile);
is the function itself
 
9:59 PM
@LewsTherin Well, you got what you asked for :)
 
Would be easier to just mmap the thing, memset it and msync it, but that depends on POSIX.
Btw what's the question?
 
@RMartinhoFernandes And to what is this an answer?
 
how to clear out a file and basically initialize it to all 0's the fastest
 
@Questioneer delete it?
 
no :p
i need to be able to re use it
without having to fopen everytime i want to clear it out and write something
 
10:03 PM
What's wrong with fopen?
There's a truncate function on POSIX btw.
6
Q: How to truncate a file in C?

sofrI'm using C to write some data to a file. I want to erase the previous text written in the file in case it was longer than what I'm writing now. I want to decrease the size of file or truncate until the end. How can I do this?

Unless you really need the zeroes (I wonder why).
 
2
Q: Zero'ing out a file

QuestioneerWhat is the most efficient quickest way to write all zeros to a file? including error checking. Would it just be fwrite? or is fseek involved? I've looked elsewhere and saw code similar to this: off_t size = fseek(pFile,0,SEEK_END); fseek(pFile,0,SEEK_SET); while (size>sizeof zeros) s...

 
@StackedCrooked lol
 
@Questioneer that's your question
 
yes it is.
This is for a simulator i'm creating to clear out parts of memory. The stuff including files fopen fwrite etc is just tests to confirm i do it. hence, is why i'm passing my function an address
 
I'm not sure I understand but to clear out parts of memory memset(ptr, 0, len) will do fine.
 
10:08 PM
yeah that seems easy enough..
 
@RMartinhoFernandes I guess you've given up on my little trivia. (I posted this here because I couldn't figure it out myself :D)
 
The buffer thing?
It looks ok from here.
 
The fastest way to zero a file is to use sparse files, obviously.
 
@RMartinhoFernandes it crashes
 
Then you can do it with a single filesystem call, usually.
 
10:12 PM
@StackedCrooked Can you do the assignments separately, and isolate the culprit?
 
@RMartinhoFernandes at least it shows problems when using debugger or valgrind. It sometimes works as a release build, if I'm (un)lucky.
@RMartinhoFernandes I
I found that it works if I use a regular pointer instead of a reference for storing the refcount.
 
Ha! I had that feeling that was trouble.
References aren't reseatable.
You're swapping the contents of the refcounts.
Not the refcount refs.
 
@RMartinhoFernandes Ok, but is that really a problem?
 
Why do your code crashes? Well, you forgot to make the context current, dummy.
 
@StackedCrooked Say, you have a buffer with a refcount at 5 and another at 2.
 
10:14 PM
(Sorry, talking to myself here.)
 
Since you swap both the refcount (contents) and the data pointer it seems to me that it will be correct in the end.
 
If you swap(rc, rhs.rc), you'll have the first buffer refcounted 2 and the other refcounted 5.
 
@RMartinhoFernandes Ok
 
> 3.2.9756 Core Profile Forward-Compatible/Debug Context
 
But then I swap the data buffers.
 
10:15 PM
But no references were actually created or destroyed or changed in any manner.
 
There are as many references to each buffer around as there were before.
I hope I managed to get that across.
 
I don't see the problem (yet). The swap simply swaps the values of the variables that each reference points too. Since the buffer pointers are also swapped the refcounts and data buffers are still correctly paired.
 
Does it make sense to separate just a few functions into a separate file?
 
I can hack up something with freehand circles to show it.
 
10:18 PM
It depends on functions.
I can create GL contexts with no deprecated stuff in them!
 
@CatPlusPlus I have a single C file to interface with terminal system calls. The stuff in there right now gets its size. I want to add some more stuff to control input.
 
@RMartinhoFernandes am I being dense? lol
I think I'll ask SO.
 
Well, are you sparse?
 
Lemme finish the circles first! Then I can get rep!
(No, go ahead and ask.)
 
@Maxpm If it feels more fuzzy to have them in a separate TU, then move them.
 
10:21 PM
@CatPlusPlus TU?
 
File.
Or you can ask robot to explain, translation unit.
I have a cold.
 
@CatPlusPlus me too
 
@StackedCrooked you asked a question on SO?
 
0
Q: Memory corruption in a small ref-counted buffer class.

StackedCrookedI have a simple reference counted class that holds a memory buffer. It looks like this: #include <algorithm> template<typename T> struct buffer { buffer(unsigned n) : rc(*(new unsigned(1))), data(new T[n]) { } buffer(const buffer<T> & rhs) : rc(++rhs.rc), data(rhs...

Earn rep!
 
Good, I'll put my circles up :)
Answered!
 
10:32 PM
Wow how did you spot that so fast
 
He put the code up a while ago.
42 mins ago, by StackedCrooked
Quiz time: Can you judge by the naked eye whether this code will work? It's small refcounted memory buffer class.
Btw, rep me up!
I had to work to make those pictures!
 
hahah
rep given!
 
Now, why aren't you using shared_ptr?
 
Someone should cat libSomeLib.a > SomeFile.txt, have it printed on a big poster, and sell it as art.
 
@RMartinhoFernandes I'm not actually sure I understand your answer
 
Oh noes, Flash!
@TonyTheLion Oh, come on, there are pictures!
 
FreeType is so painfully low level.
 
how does moving the contents of a reference with a swap actually pose a problem
 
@TonyTheLion Look at the values of the refcounts before and after.
 
10:38 PM
besides that the refcounts of the class itself won't be correct
but that's in the context of the class
not just the references and the std::swap
 
You need to imagine that there are more little circles around.
Those don't change.
And will have the bad refcounts.
Maybe I should add some.
 
I think you should
:)
 
@TonyTheLion I added another little circle that makes the nastiness more obvious.
How many references are there to buffer B? 5 or 2?
 
@RMartinhoFernandes right, I can see the refcount is obviously wrong
but how would that cause memory corruption?
 
Imagine what happens when the object on the bottom is destroyed (I updated the images with new refcounts now, no non-depicted objects required :).
 
10:50 PM
The arrows in your second picture assume thought that the swap of data member hasn't happened yet, right?
 
The arrows are after both swaps.
 
otherwise the other arrows would point to their correct buffer?
@RMartinhoFernandes oh .... wow, thats weird
 
You cannot reseat references.
Once set, they cannot refer to another object.
 
so essentially the B buffer would still reference the int from A, but with a different value?
 
Wait, maybe you're confused by my use of the word "buffer".
In the pictures the "buffer" is the actual allocated data.
Not instances of the buffer struct. Those are the little circles.
 
10:55 PM
@RMartinhoFernandes yes, I thought these two would be swapped too
 
operator= swaps the pointers to the allocated memory, but doesn't swap the "pointers" to the refcounts, because he is using references.
 
right
 
And that gets you to the second picture.
 
yea I get it now
 
Now, when the object on the bottom is destroyed, it will see a refcount that is lying.
And will do the nasties.
 
10:58 PM
oh yea, UB I guess
 
In fact, since rhs will leave scope when operator= returns, it will deallocate "Buffer A" and set "Refcount B" to 0. Then other when destroyed will decrement a 0, and overflow and get a 2^N-1. So it won't deallocate the buffer.
When *this is finally destroyed, it will decrement the "Refcount A" to 1, and not deallocate anything either.
 

« first day (368 days earlier)      last day (4562 days later) »