Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why do my format routine parameters (usually) have to be pointers to the type logged?

0
10 Posted

Why do my format routine parameters (usually) have to be pointers to the type logged?

0
10

The short answer is, “Because that’s how it works.” There are two real reasons. The first has to do with the whole logging/formatting concept. Data is copied to a memory-mapped file when logged. When formatting, we memory-map the APD file. To pass the data to the format routine directly, we’d have to allocate temporary space of the right size and copy it again. It’s much more elegant to pass everything — scalars, structs, and arrays — by pointer. That way, when you log an `int’ value, you write it to the APD file, and when you format it, you just pass its address in the memory-mapped apd file directly to the format routine. This allows ints, arrays of ints, and structs to all work the same way. The second reason is related to the first, and has to do with the fact the C doesn’t have an array “type”, but rather treats any adjacent locations in memory as an array. Here’s what our chief designer has to say on this subject: When designing the APC extensions such as ‘log’ statements we ha

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123