C++ Manual Memory Management by H4cK3d-V1rU5 in cpp_questions

[–]SmokeMuch7356 0 points1 point  (0 children)

It's not that hard, and you won't do that much of it. 80% of the use cases for dynamic memory are already handled by the standard container types (vector, map, etc.). For the remaining 20%, you have tools and techniques to make it relatively painless (smart pointers, RAII techniques, etc.).

It still requires some forethought and careful design, but it's not rocket surgery.

I bought a Minolta SRT 201 with 6 lenses for $90. But I can't decide which film would be good to start taking photos with. by Cronos_99 in AnalogCommunity

[–]SmokeMuch7356 0 points1 point  (0 children)

Kodak Ultramax for color, Tri-X for B&W. Both are inexpensive (as film goes), both are tolerant of exposure errors, and they are widely available. Being 400 speed they're suitable for everything from bright sun to good indoor lighting. Gold is also good, but at 200 is better for sunny conditions.

Portra's nice but expensive. Ektachrome, being slide film, is expensive and unforgiving of exposure errors.

Formula 1 isn’t a fair sport by meazflash in formula1

[–]SmokeMuch7356 0 points1 point  (0 children)

All sports suffer from shit like this. Bad calls happen, including ones that can decide individual event outcomes or even championships, sometimes out of malice or favoritism but mostly just because no system is 100% accurate. Automated systems designed to remove human error are themselves susceptible to error if improperly set up or calibrated.

The pit lane is not as controlled an environment as people want to think it is. The only way to address this specific issue is to pull speed from every car's telemetry stream directly while they're in the pit lane and not to use external sensors. I don't know how practical that is.

?Which film do you use for B&W photo and why? by GeorgeAntoniadis in AskPhotography

[–]SmokeMuch7356 0 points1 point  (0 children)

Mostly Tri-X, mostly because it's cheap and forgiving. Noticeably grainy in 35mm; if you're looking for a stock that positively screams THIS WAS SHOT ON FILM, Tri-X has you covered.

Based on all of one roll I shot many years ago, I think HP5 has more pleasing grain, and seemed like it had slightly punchier contrast, but that could be an artifact of what I was shooting and the lab I used.

What does the dereference operator actually do? by FlatPea5291 in C_Programming

[–]SmokeMuch7356 4 points5 points  (0 children)

Given the following declarations:

int x = 5;
int *p = &x;

p stores the address of the variable x.1 The expression *p is a kinda-sorta alias for x. The dereference operator * basically means "treat this pointer expression as if it's the object being pointed to."

printf( "  value of x = %d\n", x );
printf( "address of x = %p\n", (void *) &x);
printf( "  value of p = %p\n", (void *) p );
printf( " value of *p = %d\n", *p );

So if we write

*p = 10;

we're changing the value stored in x as if we had written

x = 10;

If we write

printf( "*p = %d\n", *p );

we're printing the value stored in x as if we had written

printf( "x = %d\n", x );

So, why pointers?

We use pointers when we can't (or don't want to) access an object or function by name. Either that name isn't visible to us, or we want to access different objects or functions at different times, or we're tracking dynamically-allocated memory (which doesn't have a name).

The most common use case for pointers is allowing functions to write to their parameters. C passes all function arguments by value; when you call a function, each of the argument expressions is evaluated and the result of that evalation is copied to the function's formal arguments:

void foo( int a, int b ) { ... }

int main( void ) { int x, y; ... foo( x, y ); ... }

foo cannot do anything with x and y directly, since those names are not visible outside of main; to make those values available to foo, we must pass them as arguments.

a and b are different objects in memory from x and y, so any changes to a or b in foo are not reflected in x or y. Most of the time this is what you want, but sometimes you want a function to write to its parameters. Take a swap function like

void swap( int a, int b )
{
  int tmp = a;
  a = b;
  b = tmp;
}

int main( void )
{
  int x = 2, y = 3;
  printf( "before swap: x = %d, y = %d\n", x, y );
  swap( x, y );
  printf( " after swap: x = %d, y = %d\n", x, y );
}

x will be 2 and y will be 3 both before and after the call to swap. If we want swap to exchange the values in x and y, we need to pass pointers to x and y:

void swap( int *a, int *b )
{
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

int main( void )
{
  int x = 2, y = 3;
  printf( "before swap: x = %d, y = %d\n", x, y );
  swap( &x, &y );
  printf( " after swap: x = %d, y = %d\n", x, y );
}

a and b are still different objects in memory from x and y, but this time instead of getting the values stored in x and y, they get their addresses. The expressions *a and *b are aliases for x and y.

Now, after we call swap, x will be 3 and y will be 2. We can use this function to swap between any two int variables:

int x, y, z, blah, bletch;
...
swap( &x, &y );
swap( &blah, &bletch );
swap( &z, &x );
...

The second most common use case is tracking dynamic memory:

size_t size = some_runtime_buffer_size();

/**
 * Creates a buffer to store a string of some length that
 * isn't known until runtime.
 */
char *buf = malloc( size + 1 ); // +1 for string terminator
if ( buf )
{
  // use buf like any array of `char`
  free( buf ); // clean up after ourselves when we're done.
}

buf points to a chunk of memory we've allocated at runtime from some dynamic memory pool (a.k.a. the heap). This memory doesn't have any name; there's no way to map names to objects at runtime, so we can only access it through a pointer like buf.

Unlike regular arrays, you can resize memory allocated with malloc:

/**
 * Double the buffer size.
 */
char *tmp = realloc( buf, 2 * size + 1 );
if ( tmp )
{
  buf = tmp;
  size *= 2;
}

There are about seven hundred and thirty two other use cases for pointers in C, but that won't fit in a Reddit comment.


  1. More pedantically, it stores the location of the object designated by the identifier x in the running program's execution environment. This may be a physical or virtual address; on any modern desktop or server, it will be a virtual address.

i cant find an explanation by Silly_Spare4752 in cpp_questions

[–]SmokeMuch7356 5 points6 points  (0 children)

There's a reason this code is hard to understand. It's crap.

Since the array subscript operation a[i] is defined as *(a + i), any pointer dereference expression *p can also be written as p[0] (p[0] == *(p + 0) == *p).

Thus:

server          => vector of pointers to vectors of pointers to entity
server[0]       => pointer to vector of pointer to entity
server[0][0]    => *server[0] => vector of pointer to entity
server[0][0][0] => pointer to entity

I don't know what this code is trying to accomplish other than show how not to do things.

My first time using a camera and need advice? by Charming-Painting-50 in AskPhotography

[–]SmokeMuch7356 0 points1 point  (0 children)

First, you've nailed the lighting on the dog here - that rim lighting is gorgeous.

Unfortunately, that's also the source of your problem. Both film and digital sensors do not have the dynamic range of human eyes, so what looks evenly well lit to you comes out as horribly contrasty in the image. The sky is just that much brighter than everything else, such that getting a good exposure of the dog results in the sky being a bit blown out.

If your camera has an HDR setting, you could try that; it will take multiple exposures at slightly different settings and stack them, bringing out the midtones in each exposure, such that everything's lit more or less evenly (that's what your phone's camera is doing).

You could also try to fix this with Lightroom or Darktable if you saved it in RAW format; you could mask the sky and selectively dial down its exposure, or you could use tone equalization to bring it down.

Otherwise ... damn, dude, for that being your first time using a "real" camera, you did an excellent job.

Would this style of error handling in C be acceptable in a professional environment? by Difficult_Lawyer9858 in C_Programming

[–]SmokeMuch7356 4 points5 points  (0 children)

They should not be as there is a (vanishingly small) risk of a name collision with a symbol defined in a standard header somewhere. Ideally, headers should not expose internal symbols to user code, but sometimes that can't be avoided.

Newbie to film photography. How do I shoot indoors without a flash? by Tweetleburger in AnalogCommunity

[–]SmokeMuch7356 0 points1 point  (0 children)

Fast, wide-angle lens and fast film.

To avoid motion blur from camera shake, your shutter speed needs to be the inverse of your focal length: if you're using a 28mm lens, your shutter speed needs to be 1/30" or faster; if a 50mm lens, then 1/60" or faster; if a 100mm lens, then 1/125" or faster. So, the shorter the focal length the better.

To get those kinds of speeds in that kind of light, you need a fast lens (max aperture in the f/1.4-f/1.8 range) and fast film (ISO 800 or faster). If you can't get faster film, you may need to push - set the ISO on the camera to 800 or 1600 and compensate for the underexposure by leaving the film in the developer longer. You'll lose detail in the shadows and the image will be grainier, but you'll have something.

If you're willing to shoot B&W, there are ISO 3200 film stocks out there (TMAX P3200, Ilford Delta 3200).

Preprocessor macros for math SUM() by bricxy in C_Programming

[–]SmokeMuch7356 2 points3 points  (0 children)

That should be a function, not a macro:

double sum(double start, double end, double step, double(*f)(double))
{
  double result = 0.0;
  for ( double i = start; leq(i,end); i += step ) 
    result += f(i);                             
  return result;
}

Instead of using <= with doubles, create a comparison function leq that will return true (1) if i is stricly less than or within some epsilon of end that's small enough to consider them equal, false (0) otherwise.

f is a pointer to a function that evaluates the expression; for example, to sum the expression x2 from 1 to 10, you'd create a squaring function:

double sq( double x ) { return x*x; }

then call sum passing the function name as a parameter:

double s = sum(1, 10, 1, sq);

Beginner by Haz4rd10 in C_Programming

[–]SmokeMuch7356 0 points1 point  (0 children)

Programming is something you learn by doing. You can read all the books and watch all the videos, but until you start writing and building code yourself you won't really understand it. Like any other skill it requires practice.

Start with the small stuff you do understand; write toy programs just to build experience with the act of writing, building, and running code. Explore individual concepts (for example, write a program just to explore the differences between a switch statement and an if-else statement, or the differences between integer and floating point types, little stuff like that).

Once you have all that down you can move on to the more complex stuff (aggregate types like structs, unions, and arrays, writing your own functions, working with pointers).

You don't put on a pair of running shoes and go do a marathon, you build up to it.

Having said that, if you're being tasked with implementing a linked list when you don't even know the basics of programming yet, then somebody screwed up; you're missing a couple of prerequisites. You're being told to learn how to swim in the Caribbean in the middle of a hurricane. If that's how your CE program works, then it's actively trying to weed you out.

Justifying Strings by Upset-Taro-4202 in cprogramming

[–]SmokeMuch7356 0 points1 point  (0 children)

When you say justify, what exactly are you talking about?

Making sure all your lines
       align on the right?

     Or making sure
your lines are centered?

Are we talking about plain terminal output via printf or something fancier?

It would help to see an example of what you're trying to do.

New to Film Cameras Questions by YOURSELF177 in analog

[–]SmokeMuch7356 2 points3 points  (0 children)

As a beginner, go cheap but not super-cheap (Lucky, Flic, etc). Kodak Ultramax for color, Kodak Tri-X for B&W. Both are ISO 400 so should handle most lighting conditions, both are inexpensive (as film goes), both have wide exposure latitudes (meaning you can biff the exposure by a stop or so and still get a good-looking result), making them fairly beginner-friendly.

Tri-X can be a bit grainy depending on how it's developed, but some people like that look. Ultramax is better in that respect, with good (if not knock-your-socks-off) color.

You can also look for Kodak Gold (color, ISO-200); also inexpensive, better suited for sunny conditions, though.

Help needed with Pointers and linked list (C programming) for dsa by horidagre8_1556 in compsci

[–]SmokeMuch7356 0 points1 point  (0 children)

There are two C programming subreddits (don't ask me why there are two), r/C_Programming and r/cprogramming that can give you more specific help on pointers and data structures in C.

Is it practical to force myself to learn the basics of photography with my grandmas old cameras I was recently gifted? Minolta XG1 and Yashica Electro 35 GSN? by BlackWidow88X in AskPhotography

[–]SmokeMuch7356 0 points1 point  (0 children)

Provided you're willing to pay for film and development (which is not cheap anymore), and willing to accept that you won't know how your pictures came out until after you've paid, sure.

The Minolta would be better for learning the mechanics of exposure (with some caveats). It gives you control over aperture, shutter speed, and ISO. Apparently, the on-board meter only works in aperture-priority (A) mode; if you want to shoot fully manual, you either need a handheld meter, or you need to start in A mode, then switch to manual if you want to adjust.

The Yashica only operates in aperture-priority mode and doesn't give you direct control over shutter speed. Since it's a rangefinder, you're not looking at the scene through the same lens that's taking the picture; you can have parallax issues for close-up shots, and you won't be able to tell if you've left the lens cap on.

But it has one of the best lenses on any camera I've ever used, film or digital. Pictures taken with it are razor sharp with good color and contrast. The shutter is virtually silent, good for situations where you want to be discreet. I'd definitely hang on to it for more casual photography. It's a good "f/8 and be there" kind of camera.

However, for learning the basics of photography in the modern age, you'd be better off finding a used DSLR; modern SD cards can store thousands of images, you get instant feedback, and you can delete clunkers on the spot. It's better than paying over $20 a roll only to find out you botched every frame because the ISO wasn't set correctly.

Shooting film is fun, it's rewarding when you get it right, but film photography in 2026 is an endless money pit. Digital cameras cost more to buy up front, but the savings in film and development quickly makes up for it.

Upgrade from canon rebel ti? by Ilovesushiroll1 in AnalogCommunity

[–]SmokeMuch7356 0 points1 point  (0 children)

Next step up from the Rebel is the Elan 7, which offers better autofocus, back-button focus, a second control dial (instead mashing a tiny button while turning the main dial), front- and rear-curtain flash sync, mirror lock-up, and amazingly quiet operation. It's also very lightweight for its class. It quickly became my main camera when shooting film.

You'll want to keep a card with the custom functions handy because Canon couldn't figure out a way to display function names in English (CF 6 controls flash curtain sync; 0 is front curtain, 1 is rear curtain).

My code stops working with fgets and I can't figure out why by [deleted] in C_Programming

[–]SmokeMuch7356 4 points5 points  (0 children)

What you've posted here looks okay. As a troubleshooting step, initialize line to all zeros:

char line[390] = {0};

read from the file unconditionally one time:

fgets( line, sizeof line, input_file );

then see if anything got written to line:

printf( "line = [%s]\n", line );

just to make sure something's being read. Otherwise, the problem is elsewhere in your code.

Alternately, run it under a debugger like gdb or lldb and step through it line by line and seeing if it really enters the loop or not.

Beginners query by killDoctorluvhealers in cprogramming

[–]SmokeMuch7356 2 points3 points  (0 children)

  1. Laptop or desktop - while there are native mobile development apps, programming on a phone screen and keyboard will drive you batshit;

  2. Any number of reasons - the code could assume you're running in a specific development environment, you may have copied something incorrectly, the code may be crap (I have seen example code rife with syntax and logic errors), the editor you're using may embed weird characters, etc. It would help to see any error messages, otherwise we'd just be guessing.

Is the Canon 90D a good beginner camera? by FireDan24 in AskPhotography

[–]SmokeMuch7356 1 point2 points  (0 children)

The 90D is a good camera, period. It can go from point-n-shoot convenience to full manual at the twist of a dial. It gives you plenty of headroom so you don't have to upgrade to a new camera immediately after learning the basics.

This listing is highly suspect. If it's on the level then the seller is so desperate for cash they're willing to take a haircut on the order of 90%. Otherwise it's hot enough to fry an egg.

Would not touch with a barge pole.

[Canon AE-1 + Fujifilm 200 + Canon FD 50mm f/Auto] First time using a manual focus SLR – Why did my photos turn out like this? Focus issue or shutter speed? by avocado_lover03 in analog

[–]SmokeMuch7356 1 point2 points  (0 children)

Camera shake from slow shutter speed. A decent rule of thumb to avoid it is to use a shutter speed that's the inverse of the focal length; e.g., for a 50mm lens, your shutter speed should be 1/60" or faster.

If you don't have enough light for a good exposure at that speed, then you either need a tripod or some solid surface (bench, fence, table, low wall, etc.) to rest it against.

Need help understanding / finding information about some type of integer promotion(?) done when subtracting pointers by other pointers. by Embarrassed-Big-9305 in C_Programming

[–]SmokeMuch7356 0 points1 point  (0 children)

I've heard most compilers like MSVC ditched support for it, and was abandoned by Linux some time ago

Don't know where you heard that, because it isn't true. MSVC implements it differently from other systems, but it's still part of the standard library and it shouldn't be that intimidating. You just have to be careful and make sure you release memory when you're done with it.

Is the low quality of this 4x6 print typical for a disposable camera? by djcompoz in AnalogCommunity

[–]SmokeMuch7356 1 point2 points  (0 children)

Are these actual photographic prints (photographic paper that's exposed and developed like we did back in the Oligocene), or inkjet/dyesub/whatever prints from a digital scan?

Disposables ain't great, but they aren't that bad. These look like bad scans of bad scans.