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?
@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"
@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.
@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
@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
> 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
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 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?
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#).
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)
I'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?
What 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...
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 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.
@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.
I 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...
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.