Skip to content

C / C++ / MFC

C, Visual C++ and MFC discussions

This category can be followed from the open social web via the handle c-c-mfc@forum.codeproject.com

111.5k Topics 465.7k Posts
  • How do you pass an int by reference to a function?

    question
    8
    0 Votes
    8 Posts
    21 Views
    Greg UtasG
    What to do depends on the environment you're running in. I've never used assert, so I had to look up the documentation, which says that it calls abort. Most application code won't catch an invalid_argument exception, so the effect will be similar. In my open-source software, I neither throw nor assert in this situation. Instead, I generate a debug log with a traceback and return whatever signifies failure if the function has a result. That's appropriate if avoiding crashes is paramount, which is what my software aims for. You're right that a reference shouldn't be null. For many functions, a pointer argument shouldn't be null either. But applications misbehave, so you have to decide whether your function will check for bad arguments or just crash. Robust Services Core | Software Techniques for Lemmings | Articles The fox knows many things, but the hedgehog knows one big thing.
  • Not a question, just a lament about metaprogramming

    c++ graphics design com game-dev
    8
    0 Votes
    8 Posts
    12 Views
    honey the codewitchH
    I do use code generation where template won't suffice, like generating state machines, but it complicates the build process. In the end metaprogramming evolved from simple GP without intrinsic language support for it and that is ultimately what I'm complaining about. Newer iterations of C++ post say 20 are starting to rectify this, and make the concepts more "first class" That will improve readability without complicating the build. Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix
  • Struct initalization valid ?

    devops question
    13
    0 Votes
    13 Posts
    21 Views
    K
    Take a look at the GCC (or clang) documentation for what -Wextra adds: [Warning Options (Using the GNU Compiler Collection (GCC))](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#:~:text=--,Wextra,-¶) . In most cases, you probably do want to be aware of all the additional warnings that -Wextra brings. But maybe in the embedded world you're going to be doing something that's going to trigger one of the warnings excessively. In which case you might just want -Wmissing-field-initializers. Or perhaps you might want e.g. -Wextra -Wno-unintialized, which gives you all of -Wextra's goodness, but silences the -Wuninitailzed warnings. If you've got a section of code that you know is going to generate warnings, and you just want to shut the compiler up you can always investigate the GCC diagnostic pragmas : [Diagnostic Pragmas (Using the GNU Compiler Collection (GCC))](https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html) Keep Calm and Carry On
  • <pre>购买护照、驾照、身份证、居留证

    com
    0
    0 Votes
    0 Posts
    8 Views
    No one has replied
  • How to extract all words - using regular expression

    regex help tutorial question
    12
    0 Votes
    12 Posts
    23 Views
    J
    Salvatore Terress wrote: learn more about using regular expression....RegExp = "[/\\w+/g]+"; Keep in mind that that form of a regular expression will be unlikely to work in any other regular expression interpreter. Perl, javascript, C# and Java (perhaps others) all use the same rules for most of the basics for regex and that will not work with any of them. For those that means the following - Match A-Za-z0-9. - Match a forward slash (redundant twice) - Match a 'g'. Redundant with the word class match.
  • called pointer is null...

    help
    9
    0 Votes
    9 Posts
    19 Views
    L
    jschell wrote: Perhaps that is the actual problem. They think they are running the code shown but the code being executed is different. Given who I suspect is asking the question I am not at all surprised. And if you look at OP's reply to Dave Kreskowiak you will see more confusion.
  • Regular expression error ?

    regex help debugging question
    12
    0 Votes
    12 Posts
    32 Views
    R
    Salvatore Terress wrote: ([0-F]{2}[:]){5}[0-F]{2}) Should be: ([0-F]{2}[:]){5}[0-F]{2}
  • How to pass parameter (pointer) to function ?

    debugging question design help tutorial
    6
    0 Votes
    6 Posts
    27 Views
    L
    SOLVED ?? This is silly , but it works text = " START DEBUG trace " ; finds first QTextEdit QTextEdit \*textEditPtr = MWCCF->centralWidget()->findChild(); or pass desired widget name (?) QTextEdit \*textEditPtr = MWCCF->centralWidget()->findChild("textEdit"); if (textEditPtr) { qDebug("Found textEdit "); textEditPtr->append(text); } else qDebug() << "Did not find any QTextEdit";
  • convert a website from php to c#

    csharp php dotnet question
    1
    0 Votes
    1 Posts
    6 Views
    No one has replied
  • SOLVED "value optimized out " C++ error

    c++ help
    4
    0 Votes
    4 Posts
    20 Views
    Richard Andrew x64R
    This is just an educated guess on my part, and I'm not a C/C++ expert by any means. Maybe the compiler is telling you that it's discarding the copy of the QStringList that is being created when you pass by value. (Especially since the value is not being used inside the function, I think the compiler might be optimising it away and letting you know.) The difficult we do right away... ...the impossible takes slightly longer.
  • Building .dll files using Makefile

    c++ java help csharp visual-studio
    6
    0 Votes
    6 Posts
    25 Views
    J
    Due to all the problems in getting this to work, and also because in the project that I was going to use I'm not saving any really personal information, I'm going to stick with PBKDF2WithHmacSHA512 for password hashing.
  • GetVCPFeatureAndVCPFeatureReply fails when called

    com json question
    5
    0 Votes
    5 Posts
    21 Views
    V
    I'm going to look for other ways to change gamma and brightness as this function has too many limitations on hardware. In the past I used SetDeviceGammaRamp[^] for changing gamma, but now it seems that function shouldn't be used anymore. If anyone has some suggestion, they are welcomed and helpful.
  • 0 Votes
    15 Posts
    64 Views
    L
    I assumed you saw something we didn't get to see, somehow. "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
  • For loop

    performance
    34
    0 Votes
    34 Posts
    182 Views
    L
    By the way in general it is not right to think of variables as being allocated anywhere, neither in memory nor in registers. Variable are not the "thing" that is allocated, and any given variable may end being in zero or more places at the same time, if you insist on looking at it like that. It's not a completely useless mental model, which is probably why it persists, but that's as a [lie-to-children](https://en.wikipedia.org/wiki/Lie-to-children). If a variable is assigned to various times (in the static sense: not so much several times in a loop, but several times in straight line code), those different "versions" of the variable may well end up in different places. SSA considers those different "versions" of the variable to be different variables altogether. Furthermore, even one "version" of a variable can be split into multiple live ranges - that's not just theoretical, there can be multiple good reasons to split it and allocated the pieces to different places. For example, there are often restrictions on which set of register can be used for some instructions, such as on x64 divisions and "legacy" shift-by-variable instructions. For example, if we consider this code with a division and shift-by-variable: int test(int x, int y) { x = x / y; return y << x; } [MSVC compiles it like this, for x64](https://godbolt.org/z/T8dGWMzhc) (why doesn't this link linkify?) 0 x$ = 8 1 y$ = 16 2 int test(int,int) PROC ; test 3 mov r8d, edx 4 mov eax, ecx 5 cdq 6 idiv r8d 7 mov ecx, eax 8 shl r8d, cl 9 mov eax, r8d 10 ret 0 11 int test(int,int) ENDP ; test On lines 0 and 1 MSVC helpfully defined stack offsets for x and y, which aren't used, they never end up being on the stack. `x` is passed in via `ecx`, and `y` via `edx`. `x` begins in `ecx`, then is copied to `eax` (line 4) because `idiv` takes the dividend in `edx:eax`, the division leaves it in `eax` (only because the code happens to assign the result of `x / y` back to `x` - to be clear, the output would be in `eax` either way, but `eax` could have represented some other variable otherwise), the original un-divided value of `x` is still in `ecx` at this point (after the division on line 6 but before the mov on line 7) but we need the new value to be in `ecx`, because `shl` needs the shift count to be in `cl` which is the
  • 0 Votes
    10 Posts
    55 Views
    L
    Well, Alot of members check the forums everyday. Sometimes it just helps to have a few other eyes look at the issue. Rick R. 2023 wrote: Have to fix a bunch of linker problems XP to Win11 is a big jump, I can imagine. :laugh:
  • fingerprint sensor code with c++

    c++ iot tutorial
    2
    0 Votes
    2 Posts
    11 Views
    CPalliniC
    Probably you mean 'how to create from scratch a C++ application interfacing a fingerprint sensor module (directly handling the fingerprint sensor would be far more difficult, I suppose). If I got you then you should carefully read the documentation of the module and implement yourself the appropriate communication code. You may also have a look at existing libraries source code (e.g. Arduino). "In testa che avete, Signor di Ceprano?" -- Rigoletto
  • write a progrrame create a calculator (using function)

    help
    8
    0 Votes
    8 Posts
    34 Views
    T
    CP could make it a requirement that with any request for having someone doing your homework for you, the name and email of the professor must be specified, so we know where to go to obtain more details about the task.
  • 0 Votes
    15 Posts
    71 Views
    T
    I am not a super-expert with macros (in my C# programming I have never used it). I do not immediately see how I can write a macro so that I can write file names in their 'true' form, without any escaping of backslashes (or for that sake, spaces, different quotes and other other characters requiring quoting in a *nix file system context. If you can show me how a macro to achieve that might look like, I would be grateful.
  • Type of array and printf specifiers

    database data-structures question
    4
    0 Votes
    4 Posts
    12 Views
    CPalliniC
    Probably you meant something similar to #include #include #include #define SIZE 10 void findbinary(int number, char result[], int index); int main (void) { int someNumber = 233; char result[SIZE]; findbinary(someNumber, result,0); printf("Decimal %d in reversed binary %s\n", someNumber, result); return 0; } void findbinary(int number, char result[], int index) { if ( index == SIZE) exit(-1); //TODO: notify the error if(number == 0){ result\[index\] = '\\0'; // append theterminator return; } result\[index\] = (number % 2) + '0'; // obtain either the CHARACTER '0' or '1' findbinary(number / 2, result, index + 1); } Note you are representing the binary number 'reversed' (that is leftmost bit is the least significant). "In testa che avete, Signor di Ceprano?" -- Rigoletto
  • Botnet

    javascript com game-dev sysadmin data-structures
    1
    0 Votes
    1 Posts
    4 Views
    No one has replied