Tag Info

Hot answers tagged

15

The big difference is that CMake is a cross-platform meta-build system. A single CMake project can produce the usual Unix/Linux makefile, a Visual Studio project for Windows, an XCode project for Mac, and almost any other non-meta build system you might want to use or support. I wouldn't say using make directly or even manually editing makefiles is ...


6

Is make really outdated? I don't think so. In the end, make is still powerful enough to provide all the functionality desired, like conditional compilation of changed source and alike. Saying make was outdated, would be the same as saying writing custom linker scripts was outdated. But what raw make doesn't provide, are extended functionalities and stock ...


6

C++ can do it the same way C does. All C++ gives you is easier-to-use containers that wrap much of the low-level detail. For example, a string class can (and does) hold a block of memory on the stack for short strings, only allocating a heap buffer for larger ones. This buffer is exactly like a C string buffer, if the string resizes, the string class will ...


6

The cleanup could be in an outer function, and then return can be used instead of goto: void main_func() { /* Set-up goes here */ handle x = ...; handle y = ...; void result = inner_func(x, y); /* Clean-up goes here */ CloseHandle(x); CloseHandle(y); } void inner_func(x, y) { if (condition1) return; if (condition2) ...


5

Using function names to differentiate among n true/false behaviors will result in 2n functions. This is easy to manage when n is a small value like 2 or 3, but it gets out of hand very quickly with anything greater. The POSIX open(2) call has nine true/false variants, and if that were written as one function per combination, you'd be staring down 512 ...


4

In C++, the pre-increment operator may be written to return a reference to the incremented object. The post-increment operator has to return a copy (because the return value is the value before the increment operation). So, if you're using increment and don't care about the return value (such as in a loop increment), then you want to prefer pre-increment as ...


4

You could try saying what you mean: if (!condition1 && !condition2 && !condition3 ) { // do stuff only if all checks passed } CloseHandle(x); CloseHandle(y); // etc. As various commenters have pointed out this is only readable/maintaibable if the condition tests are fairly simple where complex conditions are involved something like this ...


3

shared memory is not the complete picture for IPC, its a data-passing mechanism but you still need some way to inform the other process that some data has been updated and is available to be read. How you do this is up to you, typically you'd use an OS mutex or event object, each process waits on this to be set, the application writing sets it once its ...


3

Once upon a time high level languages were just an idea. People tried to implement compilers. Back then there were severe hardware limitations - there were no graphical tools so "plain text" ended up being used for the input file format; computers typically had an extremely tiny amount of RAM so the source code had to be broken into pieces and the compiler ...


3

The amount of variables (and hence, the magnitude of the combinatorial explosion) can be reduced with a more general and modular API. For example, instead of making Find support substrings, create a separate function that takes a substring out of a string. Instead of returning either the start of the end of the match, always return the start and make it easy ...


3

It sounds like you're asking how to take "http data" and convert it to "https data" so that it's automatically more secure when you send it into the internet. That's not how it works. HTTPS is a different protocol, in which SSL is used to establish a secure connection with the other endpoint before sending regular HTTP packets. Whether you want to set this ...


3

But I cannot get my head around to how the boost library does this. The boost interprocess mechanism has three necessary components to work: memory-mapped file: a memory-mapped file needs to be created and passed to a boost.interprocess allocator. This allocator will take chunks of the file and use them as if they were returned by a std::allocator, ...


2

Boost uses memory mapping of a file. Both unix and windows support creation of files that don't exist on the normal file system for just this purpose. Then you will need to synchronize access to that memory like you would if different threads were to access it. Meaning concurrent reads can happen without synchronization but as soon as one process want to ...


2

Shared memory is still just memory. You can put a mutex, spinlock or any other synchronization primitive in there, and use them to synchronize your processes' access to the shared memory, exactly like threads use those primitives to synchronize access to the memory visible to them. The only real differences are: threads share all memory and the same ...


2

Different linked libraries may use different heaps. This makes dynamic allocation and memory management tricky. The most common way is to make Person an opaque struct (declared but not defined in the public header) and the programmer using it must use the functions in the library to get access to the attributes. This means that allocating and freeing will ...


2

Your question is a matter of opinion, however, it looks like Person is generally supposed to be allocated in the heap (read about C dynamic memory allocation). Then you should define and document how Person-s are allocated and who is in charge of free-ing them and when. I would suggest to have a function to create Person-s like Person* ...


2

In C a typical way to simplify error checking and avoid deep nested if is: do { if (condition1) break; /* 1. do something... */ if (condition2) break; /* 2. do something else... */ if (condition3) break; /* 3. do something else... */ } while(0); /* Cleanup */ There are various opinion on this "idiom" (e.g. take a look at Do you consider ...


2

make (the tool or direct use of it via a Makefile) is not outdated, particularly for "small, personal projects" as you use it for. Of course, you can also use it for larger projects, including those targeted for multiple platforms. With target-specific variables you can easily customize how you build for different platforms. Nowadays, Linux distributions ...


2

Notice that C and C++ are different languages. Shared memory is impossible in purely standard C11, or C++11 (since the standard does not define that), or even C++14 (whose n3690 draft, and presumably official standard, does not mention shared memory outside of multi-threading). So you need extra libraries to get shared memory. But some operating systems ...


1

I don't think that human written Makefile-s are obsolete, especially when: using POSIX make, which gives you a portable Makefile or using GNU make 4, which gives you many very interesting features, in particular GUILE scriptability, which enables to code efficiently the fancy features provided by Makefile generators (I believe that the features of ...


1

Makefiles are not obsolete, in the same way that text files are not obsolete. Storing all data in plain text is not always the right way of doing things, but if all you want is a Todo List then a plain text file is fine. For something more complicated you might want a more complicated format like Markdown or XML or a custom binary format or anything in ...


1

A trivial example of where the function calling fork is supposed to return in both the parent and the child is if the function calling fork is a simple wrapper function, and the caller of that function is the one that chooses what to do in the parent, and what in the child. A simple wrapper function might not make much sense for pure C, but POSIX C++ ...



Only top voted, non community-wiki answers of a minimum length are eligible