Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:34:06+00:00 2026-06-02T18:34:06+00:00

error: cast from ‘void*’ to ‘unsigned int’ loses precision error: invalid conversion from ‘unsigned

  • 0

error: cast from ‘void*’ to ‘unsigned int’ loses precision

error: invalid conversion from ‘unsigned int’ to ‘unsigned int**’

can u tell me how to properly cast this, i am getting error on this line:

color = (unsigned int)malloc(height*sizeof(unsigned int));

inside the main function.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

unsigned int width;
unsigned int height;
unsigned int **color = NULL;

bool file_write()
{
     FILE *fractal = fopen("mandelbrot_imageSequential.ppm","w+");
    if(fractal != NULL)
    {
            fprintf(fractal,"P6\n");
            fprintf(fractal,"# %s\n", "Mandelbrot_imageSequential.ppm");
            fprintf(fractal,"%d %d\n", height, width);
            fprintf(fractal,"40\n");
            int x = 0, y = 0;
            unsigned int R = 0, G = 0, B = 0;
            for(x = 0; x < width; ++x)
            {
                    for(y = 0; y < height; ++y)
                    {
                            R = (color[y][x]*10);
                            G = 255-((color[y][x]*10));
                            B = ((color[y][x]*10)-150);
                            if(R == 10) R = 11;
                            if(G == 10) G = 11;
                            if(B == 10) B = 11;
                            putc(R, fractal);
                            putc(G, fractal);
                            putc(B, fractal);
                    }
            }
            fclose(fractal);
    }
    return true;
}
int method(int x, int y, double min_re, double max_re, double min_im, double max_im, int max_iterations)
{
    double threshold = 4;
    double x_factor = (max_re-min_re)/(width-1);
    double y_factor = (max_im-min_im)/(height-1);
    double c_im = max_im - y*y_factor;
    double c_re = min_re + x*x_factor;
    double Z_re = c_re, Z_im = c_im;
    unsigned int col = 0;
    for(unsigned n = 0; n < max_iterations; ++n)
    {
        double Z_re2 = Z_re*Z_re, Z_im2 = Z_im*Z_im;
            if(Z_re2 + Z_im2 > threshold)
            {
                    col = n;
                    break;
            }
            Z_im = 2 * Z_re * Z_im + c_im; 
            Z_re = Z_re2 - Z_im2 + c_re;
    }
    return col;
}


void method1(double min_re, double max_re, double min_im, double max_im, int max_iterations)
{  
    for(int x = 0; x < width; x++)
    {
            for(int y = 0; y < height; ++y)
            {
                    int m1 = method(x,y,min_re,max_re,min_im,max_im,max_iterations);
                    if(m1)
                    {
                            color[x][y] = m1*50;
                    }
            }
    }
}
int main(int argc, char *argv[])
{
     unsigned int max_iterations;
     int x,y;
     double threshold;
     double min_re;
     double max_re;
     double min_im;
     double max_im;
     unsigned int NUM_OF_THREADS;
if(argc != 10)
{
    printf("There is an error in the input given.\n");
    return 0;
}
else
{
    height = atoi(argv[1]);
    width = atoi(argv[2]);
    max_iterations = atoi(argv[3]);
    min_re = atof(argv[4]);
    max_re = atof(argv[5]);
    min_im = atof(argv[6]);
    max_im = atof(argv[7]);
    threshold = atoi(argv[8]);
    NUM_OF_THREADS = atoi(argv[9]);
    }
color = (unsigned int)malloc(height*sizeof(unsigned int));
printf("height = %d\twidth = %d\tmaximum_iterations = %d\tminimum_x-value = %.2f\tmaximum_x-value = %.2f\tminimum_y-value = %.2f\tmaximum_y-value = %.2f\tthreshold_value = %.2f\tno. of threads = %d\t\n",height,width,max_iterations,min_re,max_re,min_im,max_im,threshold,NUM_OF_THREADS);
for(x = 0; x < height; x++)
{
    color[x] = (unsigned int*)malloc(width*sizeof(unsigned int));
}
time_t ts,te;
time(&ts);
method1(min_re, max_re, min_im, max_im, max_iterations);
time(&te);
double diff = difftime(te,ts);
file_write();
printf("Total Time elapsed: %f\n",diff);
return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:34:07+00:00Added an answer on June 2, 2026 at 6:34 pm
    color = (unsigned int**)malloc(height*sizeof(unsigned int*));
    

    Shouldn’t it be this?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Subsonic 2.2 is throwing the error subsonic Invalid cast from System.Int32 to System.Byte[] When
I have: unsigned char *foo(); std::string str; str.append(static_cast<const char*>(foo())); The error: invalid static_cast from
What .NET method has this error message: Object cannot be cast from DBNull to
I am trying to cast from an int to an enum, unsuccessfully, as follows:
When I do the following, I get this error: ../src/Sample.cpp:19: error: cast from \u2018UINT8*\u2019
Why i get this error? Object cannot be cast from DBNull to other types.
Error shown from the below code is: Cannot Cast an object to integer. I
How to solved error Unable to cast object of type 'System.Int32' to type 'Microsoft.DirectX.Direct3D.VertexShader'
The compiler (VC8) error is: error C2680: 'std::_Tree<_Traits>::iterator' : invalid target type for dynamic_cast
Error : Error 1 bin\Debug\Daemon.exe.manifest;bin\Release\Daemon.exe.manifest is an invalid value for the InputManifest parameter of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.