|
Can someone tell me if this code works to copy a binary file?
while ((ch = fgetc(source)) != EOF) {
fputc(ch, target);
}
What if the file contains a byte that is 255?
Won't it get converted to -1 and break the loop?
Thank you.
|
|
|
|
|
Depends on declaration of ch . If it’s an int (as it should), all is fine as 255 != -1 . If it’s char , it fails, with or without compiler warnings.
Mircea
|
|
|
|
|
|
While your method may work, assuming that ch is an int, and so does not have the 255/-1 issue, your method is horribly inefficient. Richard's suggestion to use fread/fwrite produces much better performance.
For example, given an 8M file, looping through your code 100 times took about 32 seconds. Using a fread/fwrite using a 4K buffer, the same 100 lops took just under 1 second to complete. This was on a PI-3, and successive runs remained stable. I'd expect an 8M file to sit comfortably in the file cache, so the difference is totally down to the difference between extracting a single char at a time, and reading a lot of characters at a time.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
From CP newsletter
The Myth of Smart Pointers – Logikal Blog[^]
Basically complaining about what unique_ptr<t> is defined as.
Myself reading it and looking at the code it seems to me that the author does not understand the difference between the C++ specification and the C++ compiler/runtime.
Which has always been a problem for some people using C/C++ pointers since C (before C++ existed.)
The author seems to be suggesting that the specification is guaranteeing that the memory will be collected. But without even reading the spec I seriously doubt it says that. I suspect it is noting that the it might be collected so one should not rely on it.
There are multiple other places where one can do similar things and it might or might not work depending on compiler, binary and even execution flow (which is really fun to debug.)
Perhaps I am mistaken in what I am reading?
|
|
|
|
|
Given the fact that he is breaking all the rules by branching off into QML (whatever that is, and by his own comments something to be avoided) and Javscript, then you cannot expect C++ to know what is happening outside.
|
|
|
|
|
jschell wrote: The author seems to be suggesting that the specification is guaranteeing that the memory will be collected. But without even reading the spec I seriously doubt it says that. I suspect it is noting that the it might be collected so one should not rely on it. Of course it doesn't guarantee. Where the memory is coming from and where it is going to, is outside the scope of the language specification. From C++11 to C++23 there was some kind of support for garbage collection using std::declare_reachabl e, but it was deleted[^].
Mircea
|
|
|
|
|
It was a silly article, going out of his way to create a bug and then blaming it on the thing he just intentionally broke.
But doing things with C++ that rely on platform/compiler specific details is explicitly allowed, and frequently necessary. The C++ specification alone does not make enough guarantees to result in a useful system - intentionally, so that the details can differ.
|
|
|
|
|
Voluntarily removed - posted in wrong forum...
modified 3-Dec-23 14:27pm.
|
|
|
|
|
37 Questions asked in 2 months starts leaning towards a "Help Vampire". You have not shown us in your code above what you have tried apart from 4 lines of code, which oddly looks AI generated. Please tell us what you have researched so far on how to add second primary menus. If this errors, show the error and we will gladly assist from there.
|
|
|
|
|
|
I’m trying to display an animated bitmap in a win32 application with GDIplus. Last time when I talked about this here I was told I should invalidate a rectangle to force the App to refresh/draw another frame. I’m trying to understand the theory for now. I will come up with code in a day or two if necessary. My question is do you create and invalidate between beginpaint and endpaint a rectangle that has no particular purpose or does it have to be a rectangle that actually does something.
I’m having a difficult time understanding the connection between a rectangle and the rendering process of a win32 api window
|
|
|
|
|
Roughly speaking, the invalidated rectagle will be redrawn in the next WM_PAINT call (other parts of the client area are not redrawn). So, if you need to update a portion of the client area then invalidate the corresponding rectangle and then call UpdateWindow() .
In simple scenarios you can invalidate the entire client area and then call UpdateWindow() .
See, for instance: Invalidating the Client Area - Win32 apps | Microsoft Learn[^].
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Basically I need a rectangle taking the whole window for my game, I think I understand, I’ll post a followup if I’ll run into trouble setting things. Thank you.
|
|
|
|
|
You are welcome.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
The only things you should be doing between BeginPaint and EndPaint is redrawing/rewriting the parts of the client window that may have changed. Outside of the WM_PAINT handler, you decide which part (or all) of the window needs to be repainted. You then set those values into a call to InvalidateRect , which will post a WM_PAINT message to your message queue.
|
|
|
|
|
>The only things you should be doing between beginpaint and endpaint
I was thinking to disregard everything that was rendered in one frame, and then render things all over again. Keeping track of pieces that visually change in my game ( if that’s what you mean) seems like a burden at this point.
So far I’m only looking for a way to trigger a new paint event
modified 2-Dec-23 3:45am.
|
|
|
|
|
You are welcome to do that, but it may affect the performance in certain scenarios.
|
|
|
|
|
|
It all seems a bit odd until you understand that everything in Windows is message driven. For each message type that you handle you need an event handler, for all the others just let Windows deal with them.
|
|
|
|
|
I might do some searching through CP. There are some excellent articles covering the madness of Windows drawing, GDI, etc. DCs, their variations and purposes are also covered pretty well.
Just keep in mind the point behind InvalidateRectangle - GDI is somewhat smart. It will limit it's drawing to regions it knows it needs to re-draw which is why you need an InvalidateRectangle call.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
Addendum
Since I cannot figure out ( user fault ) how to post pictures here ....
If it is OK to post a link to another forum ?
another "include " issue - how to print the path | Qt Forum[^]
Hope nobody gets uptight with basic question...
Here is how QT .pro "links" with BT_Utility_Library,
now I need to add "include" CORRECT BT_Utility_Library header.
I will freely admit that I have newer mastered "../.." - whatever it is called -
and intelisense is not helping.
Can you help me ?
Thanks
unix:!macx: LIBS += -L$$OUT_PWD/../../../CCC_SOURCE/BT_Utility_Library/ -lBT_Utility_Library
INCLUDEPATH += $$PWD/../../../CCC_SOURCE/BT_Utility_Library
DEPENDPATH += $$PWD/../../../CCC_SOURCE/BT_Utility_Library
|
|
|
|
|
single dot is the current directory, double dots are one level UP (closer to the root directory) from where you are. So backtrack to the root and then go down the correct path.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
I’m begging you for the benefit of everyone, don’t be STUPID.
|
|
|
|
|
Adding to what the other reply said.
Salvatore Terress wrote: -L$$OUT_PWD/../../../CCC_SOURCE/BT_Utility_Library/ -lBT_Utility_Library
In that '$OUT_PWD' is a directory.
Then each '..' moves UP the directory tree. So it moves up three levels.
Then it expects to find CCC_SOURCE
Whether it does so depends on whether '$OUT_PWD' is set to a correct value.
This can be further complicated by whether '$OUT_PWD' is a full directory or a partial directory. So if it is something like './MyStuff/Programs' (where the dot is important) then it is a partial directory. But if there is no dot then it is a full directory that must exist at the root of your file system.
|
|
|
|
|
Each double dot means move up to the parent of the current directory. The variable $$PWD will refer to the current directory, when this statement is processed. So assuming a project tree like:
home
-- terress
-- dev
-- myproject
-- btsamples
-- test -> assume this is $PWD
then the above statement will expect to find BT_Utility_Library in a directory named CCC_SOURCE in /home/terress/dev .
|
|
|
|