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 7705335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:50:32+00:00 2026-05-31T23:50:32+00:00

i am getting an error: invalid lvalue in assignment. this is the only error

  • 0

i am getting an error: invalid lvalue in assignment.

this is the only error with my program, it looks like a fatal compile time error regards on specially pthread.

i am trying to get the inputs in the runtime, using command line arguments, that’s why i am getting an error, but previously i didn’t get any error, when i run the program in static input initialized in the program itself.

#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <time.h>
#include <sched.h>
#include <sys/types.h>
#include <math.h>
#include <time.h>
#include <sys/time.h>
#include <stdint.h>
#define num_threads 8
pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
unsigned int width = 1500;
unsigned int height = 1500;
unsigned int max_iterations = 30000;
unsigned int **color = NULL;
double min_re;
double max_re;
double min_im;
double max_im;
double x_factor;
double y_factor;
unsigned int NUM_OF_THREADS;
int chunk = 10;
int total_sum = 0;

bool file_write()
{
FILE *fractal = fopen("mandelbrot_imagepthread.ppm","w+");
if(fractal != NULL)
{
 fprintf(fractal,"P6\n");
    fprintf(fractal,"# %s\n", "Mandelbrot_imagepthread.ppm");
    fprintf(fractal,"%d %d\n", height, width);
    fprintf(fractal,"255\n");

 int y = 0, x = 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)%255;
            G = 255-((color[y][x]*10)%255);
            B = ((color[y][x]*10)-150)%255;
      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, int max_iterations, double max_im,double min_re,double x_factor, double y_factor)
{
    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 > 4)
                {
                    col = n;
                    break;
                }
                    Z_im = 2 * Z_re * Z_im + c_im;
                    Z_re = Z_re2 - Z_im2 + c_re;
        }
    return col;
}
void* method1(void* t)
{
double min_re = -2.0;
double max_re = 1.0;
double min_im = -1.2;
double max_im = min_im+(max_re-min_re)*height/width;
double x_factor = (max_re-min_re)/(width-1);
double y_factor = (max_im-min_im)/(height-1);
int x,y;
int sub_total = -1;
pthread_mutex_lock(&mut);
if(total_sum < height)
{
    sub_total = total_sum;
    total_sum = total_sum + chunk;
}
pthread_mutex_unlock(&mut);
while(sub_total > -1)
{
    int start_point = sub_total;
    int end_point = start_point + chunk;
    for(y=start_point; y<end_point; y++)
    {
        for(x=0; x<width; ++x)
        {
            int m1;
            uintptr_t m2;
            m2 = (uintptr_t)t;
            m1 = method(x,y,max_iterations,max_im,min_re,x_factor,y_factor);
            if(m1)
            {
                color[x][y] = m1*40;
            } 
        }
    }
    sub_total = -1;
    pthread_mutex_lock(&mut);
    if(total_sum < height)
    {
        sub_total = total_sum;
        total_sum = total_sum + chunk;
    }
    pthread_mutex_unlock(&mut);
}
  pthread_exit((void*)&t);
} 
int main(int argc, char *argv[])
{
if(argc != 9)
{
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]);
num_threads = atoi(argv[8]);
}
color = (unsigned int**)malloc(height*sizeof(unsigned int*));
x_factor = (max_re-min_re)/(width-1);
y_factor = (max_im-min_im)/(height-1);
printf("height = %d\twidth = %d\tmaximum_iterations = %d\tminimum_x-value = %.2f\tmaximum_x-value = %.2f\tminimum_y-value = %.2f\tmaximum_y-value = %.2f\tno. of threads = %d\t\n",height,width,max_iterations,min_re,max_re,min_im,max_im,num_threads);
int x;
for(x = 0; x < height; x++)
{
color[x] = (unsigned int*)malloc(width*sizeof(unsigned int));
}
time_t ts,te;
time(&ts);
pthread_t t1[num_threads];
pthread_attr_t attr;
int l1;
void *att;
double value = 0.0;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
for(int i=0;i<num_threads;i++)
{
    l1 = pthread_create(&t1[i], &attr, method1, (void *) i);
    if(l1)
    {
        printf("There is some kind of error in thread creation: %d", l1);
        exit(-1);
    }
}
pthread_attr_destroy(&attr);
for(int i=0;i<num_threads;i++)
{
    l1 = pthread_join(t1[i],&att);
    if(l1)
    {
        printf("There is some kind of error in thread creation: %d", l1);
        exit(-1);
    }
    double result = *(double *)att;
    value += result;
 }
time(&te);
double diff = difftime(te,ts);
file_write();
printf("Total Time elapsed: %.2f seconds\n",diff);
for(x = 0; x < height; x++)
{
    free(color[x]);
}
free(color);
return 0;
pthread_exit(NULL);

}

  • 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-05-31T23:50:33+00:00Added an answer on May 31, 2026 at 11:50 pm

    The error here is that you define num_threads to be 8 with a #define directive instead declaring it as int!
    Change #define num_threads 8 to int num_threads=8;

    In general you should avoid #define directives because they are evil.
    If you want to have a global constant variables declare it as static const rather than a #define. Those directives are substituted by the preprocessor to the following code and lead to the following (non-sense) code.

    8 = atoi(argv[8])

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

Sidebar

Related Questions

I'm getting the invalid lvalue error using gcc 3.4.6. The line that invokes the
I'm getting this error: The remote certificate is invalid according to the validation procedure.
I am getting this error: Data at the root level is invalid. Line 1,
After compiling the program I am getting below error invalid operands of types int
I keep getting this error: Invalid Signature - This error occurs when you have
I'm trying to compile some code, but I'm getting an error: Error invalid conversion
I'm getting this error: Error: invalid conversion from int (*)(const char*, fuse_file_info*) to int
I am getting this error Invalid character line 6254 character 9 the code there
I'm getting the error Invalid argument supplied for foreach() even though the array being
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':

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.