|
You may want to check out NASM[^]
|
|
|
|
|
What`s sets them apart from each other? Will they produce binary for everything that runs on AMD/Intel processors (taken that you link to the appropriate libraries)? Are there standards that ASM code needs to meet to run on any specific OS?
|
|
|
|
|
I am writing code for an ARM processor and compiling with GCC inside Eclipse IDE. My project has 3 files, main.c, myDummyFile.h and myDummyFile.cpp. myDummyFile.h:
#ifndef MYDUMMYFILE_H_
#define MYDUMMYFILE_H_
#ifdef __cplusplus
extern "C" {
#endif
int myDummyFunction();
#ifdef __cplusplus
} #endif
#endif /* MYDUMMYFILE_H_ */ myDummyFile.cpp:
#include <functional>
using namespace std;
using cPlusPlusCallback_t = function <int(int myParam)>;
volatile int preventOptimizationDummy = 0;
int myDummyFunction() {
return preventOptimizationDummy++;
} main.c:
#include <stdio.h>
#include <stdlib.h>
#include "myDummyFile.h"
int main(int argc, char* argv[]) {
return myDummyFunction();
} Does anybody know why I get the error message "undefined reference to `myDummyFunction'" when I try to compile this? If I remove the call to myDummyFunction() then it compiles fine so the compiler does seem to be able to compile .cpp-files.
|
|
|
|
|
You need to add the following line to myDummyFile.cpp:
#include "myDummyFile.h"
Otherwise the compiler will generate a decorated* name for myDummyFunction , because the source file is C++ not C.
*In C++ external names have additional characters so the linker will not match what is called from your main file.
|
|
|
|
|
I know that SHGetFileInfo will get me the icon that is displayed for a known file type (by the file extension,) but how do I get the icon that the shell displays for an executable file? In other words, I don't want an icon from the system image list, I want the one for the executable file.
Any pointers are much appreciated.
SOLUTION: I found the ExtractIconEx function, which does what I need.
The difficult we do right away...
...the impossible takes slightly longer.
modified 9-Sep-20 21:32pm.
|
|
|
|
|
I am writing code for an ARM processor and compiling with GCC. I have done some C# programming and there you're allowed to pass anonymous arrays and structs directly in method calls:
MyClass.MyMethod1(new byte[]{0, 1, 2, 3}); and
MyClass.MyMethod2(new MyStruct("", 0, null)); What's the closest thing I can achieve the same thing in my ARM-project?
myFunction1({0, 1, 2, 3}); myFunction2({"", 0, NULL}); I understand that I could change my function to take a function pointer instead of a struct as a parameter using the technique described in Re: What's the closest thing to anonymous function pointers I can achieve that compiles with GCC? - C / C++ / MFC Discussion Boards[^]:
#include <functional>
using namespace std;
using getMyStructCallback_t = function <struct MyStruct*()>;
void myFunction(getMyStructCallback_t getMyStructCallback);
myFunction([]() {
static struct MyStruct myStruct = {"", 0, NULL}; return &myStruct;} ); but if possible, then I would like to pass my struct/array directly.
|
|
|
|
|
Check this:
struct MyStruct
{
const char* s;
int i;
void* ptr;
};
class MyClass
{
public:
MyClass ();
void MyMehod1 (const std::vector<int>& v) {};
void MyMethod2 (const MyStruct& s) {};
};
int main()
{
MyClass c;
c.MyMehod1 ({ 0, 1, 2, 3 });
c.MyMethod2 ({ "", 0, nullptr });
}
Mircea
|
|
|
|
|
Is it possible to do without classes/object orientedness?
|
|
|
|
|
Your question had this code:
MyClass.MyMethod1(new byte[]{0, 1, 2, 3});
Here you a calling a method (also called member function) of an object. So your code is already object oriented.
Maybe you should revise/clarify what you want to accomplish.
Mircea
|
|
|
|
|
That was a C# example, to indicate that I was looking for the corresponding C/C++ syntax for my ARM-project. I try to keep my ARM-code as close to pure C-programming as possible (this will obviously be an exception) and never use classes in the ARM-project. Is anything in your example dependent on the classes or will it compile just fine without classes? I'm not at work so I can't try it for myself right now, but I plan to work on this first thing in the morning.
|
|
|
|
|
arnold_w wrote: I try to keep my ARM-code as close to pure C
arnold_w wrote: I plan to work on this first thing in the morning. When you get back into the office please print out __STDC_VERSION__ so we know which language version you are working under. The C99 language and below had no support for anonymous structures or unions. But the GCC compiler has a non-standard extension -std=gnu99 that enables it.
Support for anonymous structures or unions was added in C11[^] back in 2011
If your __STDC_VERSION__ is 199901L or above then you should be able to use anonymous objects.
Best Wishes,
-David Delaune
|
|
|
|
|
You could do something like:
void Function(const std::vector<uint8_t>& values) Call it as follows:
Function(std::vector<uint8_t>{ 5, 4, 3}); (Works with VC++ 2017. Should work with GCC.)
|
|
|
|
|
Joe Woodbury wrote: void Function(const std::vector<uint8_t>& values)
Is there anything preventing me from having an override pure C-function (in addition to your C++ function) as follows:
void Function(uint8_t* values) ?
I'm thinking that in that case I would have functions that can be called both from files with .c-extension and .cpp-extension? I'd image const std::vector<uint8_t> stores bytes in memory exactly the same way uint8_t* (or uint8_t[]) does, right?
|
|
|
|
|
In C++, you could overload Function, but you'd have to do the normal #ifdef stuff to call Function from C. (Yes, by standard std::vector stores data contiguously.)
The problem is that the C function is rather dangerous.
|
|
|
|
|
Note that C arrays do not include length information! So unless your function Function(uint8_t*) somehow knows how many elements there are, you'd also have to pass the number of elements as a separate parameter! And even if it does know how many elements to expect, there's always a chance someone calls it accidentally with a different number of elements.
The class std::vector behaves like an array, but internally it does store the array length which makes the code examples above feasible. You could of course write a C++ wrapper that calls a C function internally, like this:
void Function(uint8_t* values, unsigned long int size); void Function(const std::vector<uint8_t>& values) {
Function(values.data(), values.size());
}
int main() {
Function({1, 2, 3});
return 0;
}
Otherwise, you'd have to think of another way to pass the element number reliably.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Today I saw the following syntax:
uint16_t getUint16Value(int someParameter) {
}
void myFunction() {
uint16_t destArray[2];
memcpy(destArray, (uint16_t[2]){getUint16Value(0), getUint16Value(1)}, sizeof(uint16_t[2]));
} Now, what made me really surprized about this code is that it was inside a .c-file, not a .cpp-file! I looked in the GCC documentation and tried to find examples of clever syntax like this, but I couldn't find any. Does anybody know where I can examples of anonymuous "things" (arrays, structs, function-pointers, etc) that GCC allows in C-code?
modified 11-Sep-20 18:53pm.
|
|
|
|
|
I have a dilemma over whether I should create a User Interface thread or a Background thread to process my background operations.
The docs for the function SHGetFileInfo say that it should not be called from the application's main thread because it can lock up the UI.
So I will use a secondary thread. And I will post messages to the thread to prompt it to process stuff.
But should I use the UI thread version of AfxBeginThread because it includes a message pump, or should I use the background thread version and implement my own message pump?
I ask because I do not want the application to terminate when the secondary thread terminates. My understanding of the docs is that that could happen if I use a UI thread.
Thank you
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I don't have personal experience with this function but Microsoft doc seems pretty specific:
Quote: You should call this function from a background thread. Failure to do so could cause the UI to stop responding. So background thread it is!
Mircea
|
|
|
|
|
Yes, I was taken aback when I first saw that.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
Richard Andrew x64 wrote: I ask because I do not want the application to terminate when the secondary thread terminates. My understanding of the docs is that that could happen if I use a UI thread.
Could you show me what you are referring to? The only way that I am aware of... where a CWinThread can terminate the main thread is if you reach across threads to execute code. If a WM_QUIT arrives during that short period I believe it gets posted to the main threads message queue.
Don't do this:
ThreadA->ThreadB_DoSomething();
ThreadB->ThreadA_Dosomething();
Instead post a message WM_THREAD_A_DOSOMETHING
As long as ThreadA never touches ThreadB you shouldn't have any problems. Also don't create any windows or enter any modal modal loops from your CWinThread worker thread... do all window management from your main thread.
Follow these rules:
1.) Do all window creation in your main thread.
2.) Don't reach across threads to execute code.
3.) Use PostMessage to communicate between threads.
You *can* break these rules but make sure that you fully understand the consequences and how to get around them. Raymond Chen explains how you can get around messages are eaten by modal loops[^] here.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you for the detailed response.
So you would recommend the UI version of CWinThread because it has a message pump already?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Well,
Richard Andrew x64 wrote: So you would recommend the UI version of CWinThread because it has a message pump already? Even if you used a non-gui thread.... the Windows kernel auto-promotes a thread via KiConvertToGuiThread and increases the thread stack-size and gives it a message queue immediately when it makes a syscall[^] above 0x1000.
In other words... as soon as you make your call to SHGetFileInfo[^] your thread will become a UI thread. You could prevent the auto-promotion by setting PROCESS_CREATION_MITIGATION_POLICY_WIN32K_SYSTEM_CALL_DISABLE_ALWAYS_ON but that would break your SHGetFileInfo and a myriad of other win32k system calls.
You can use CWinThread and just follow the rules I laid out in my previous response.
Best Wishes,
-David Delaune
|
|
|
|
|
Wow!
|
|
|
|
|
Hello.
I need your help.
First of all, I hope you understand that the sentence structure can be strange as I ask questions using a translator machine.
I'm looking for group policy editor api.
Especially, Local Computer Policy/Computer Configuration/Administrative Templates/System/Removable Stroage Access area.
When I changed this part, I found a registry that was created or disappeared.
But what I want is to be able to modify this group policy directly.
Because even if the registry is modified, as a result, the registry is changed to data corresponding to the group policy.
If you know the api that can modify the group policy editor, please let me know.
Thank you.
|
|
|
|
|