Friday, June 26, 2020

Digest for comp.lang.c++@googlegroups.com - 4 updates in 3 topics

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Jun 26 11:38AM -0700

On 6/23/2020 9:46 AM, Mr Flibble wrote:
> There isn't one and there never should be: we have neoGFX for that! :D
 
> /Flibble
 
Graphics in C++? How about C?
 
http://codepad.org/lkknRnxq
 
____________________
 
/* Mandelbrot Set ASCII by Chris M. Thomasson :^)
______________________________________________________*/
 
 
#include <stdio.h>
 
 
#define SQ(mp_n) ((mp_n) * (mp_n))
 
 
 
 
struct mbrot_cp_pixel
{
double x;
double y;
};
 
 
struct mbrot_cp_plane
{
double xmin;
double xmax;
double ymin;
double ymax;
};
 
 
struct mbrot_vp_plane
{
unsigned int width;
unsigned int height;
};
 
 
 
 
void
mbrot_pixel(
struct mbrot_cp_pixel const* pixel_c,
unsigned int const imax
){
int i = 0;
struct mbrot_cp_pixel pixel_z = { 0.0, 0.0 };
struct mbrot_cp_pixel pixel_z_sq = { 0.0, 0.0 };
 
for (i = 0; i < imax; ++i)
{
pixel_z.y = pixel_z.x * pixel_z.y * 2.0 + pixel_c->y;
pixel_z.x = pixel_z_sq.x - pixel_z_sq.y + pixel_c->x;
 
pixel_z_sq.x = SQ(pixel_z.x);
pixel_z_sq.y = SQ(pixel_z.y);
 
if (pixel_z_sq.x + pixel_z_sq.y > 4.0)
{
putchar(' ');
return;
}
}
 
putchar('*');
}
 
 
void
mbrot_plane(
struct mbrot_cp_plane const* cp_plane,
struct mbrot_vp_plane const* vp_plane,
unsigned int const imax
){
unsigned int vpyi = 0;
 
struct mbrot_cp_pixel cp_pixel = { 0.0, 0.0 };
 
double const cp_width = cp_plane->xmax - cp_plane->xmin;
double const cp_height = cp_plane->ymax - cp_plane->ymin;
 
double const xstep = cp_width / vp_plane->width;
double const ystep = cp_height / vp_plane->height;
 
for (vpyi = 0; vpyi < vp_plane->height; ++vpyi)
{
unsigned int vpxi = 0;
 
cp_pixel.y = cp_plane->ymax - vpyi * ystep;
 
for (vpxi = 0; vpxi < vp_plane->width; ++vpxi)
{
cp_pixel.x = cp_plane->xmin + vpxi * xstep;
 
mbrot_pixel(&cp_pixel, imax);
}
 
putchar('\n');
}
}
 
 
 
 
int
main(void)
{
struct mbrot_cp_plane const cp_plane = { -2.0, 1.0, -1.0, 1.0 };
struct mbrot_vp_plane const vp_plane = { 64, 32 };
 
mbrot_plane(&cp_plane, &vp_plane, 64);
 
return 0;
}
 
____________________
 
 
;^)
Bart <bc@freeuk.com>: Jun 26 06:34PM +0100

On 26/06/2020 17:36, Juha Nieminen wrote:
 
> No, it's not. It can only render triangles and 1-pixel-width
> non-antialiased lines and pixels. That's it. Has absolutely
> no support for anything else.
 
That's what many think of as vector graphics. After all you pass it the
endpoints of a vector, not the intervening pixels. And it can do
antialiased lines of sorts.
 
But no it doesn't have the sort of control you can get with PostScript,
a 2D renderer designed for documents and illustrations, with lines of
any thickness and control over corners and endpoints.
 
OpenGL also supports texture mapping (this is from my nearly 20-year-old
knowledge so it's probably moved on).
Juha Nieminen <nospam@thanks.invalid>: Jun 26 04:46PM


> Not for pointers. In this case "hello world" is stored in the text portion
> of the binary and is at a fixed location from the minute the binary is loaded
> into memory and is never instantiated.
 
First you describe in detail how the string literal is instantiated
and then you say that it's never instantiated.
 
>>be duplicated in every compilation unit where it's used (whether the
 
> Or more likely you'll get a duplicate symbol error unless you declare it
> as extern in all but 1 of those units.
 
Not if you declare it as const. In C++ variables at the global or
a namespace scope declared as const have internal linkage.
Paavo Helde <eesnimi@osa.pri.ee>: Jun 26 08:29PM +0300

>> instead of cc.
 
> Its the same compiler and AFAIK const <type> const <var> is not a valid C
> declaration.
 
This is not what we have; we have const <type> * const <var>, which is
legal in both languages, but with subtle differences.
 
> func 0x104109f9f
 
> Same result. Plus its poor form not to use extern when dealing with multiple
> object files since it avoids precisely these sorts of issues.
 
This means your linker performs some optimizations even without -O1.
 
In C++ namespace-level const variables have internal linkage by default,
extern would mean the opposite. If you printed out &ptr in addition to
ptr values, you would see these are different (at least if the address
of ptr is taken), even though they will point to the same string literal
if the other has been optimized away.
 
So, in C++ const global variables do not cause linker errors, and any
seemingly duplicate string literals can be easily optimized away by the
linker. No need to complicate your life with 'extern' and conditional
compilation.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: