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

  • Home
  • SEARCH
  • 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 8449707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:46:55+00:00 2026-06-10T10:46:55+00:00

I am using Code-Blocks with the mingw GCC compiler for windows to code my

  • 0

I am using Code-Blocks with the mingw GCC compiler for windows to code my program in C. I have a function defined where the input is an array of type int. I have another struct defined as

typedef struct {
float re;
float im;
}complex_float;

I want to convert the int type array to a complex_float type array as I need to process the data in the complex_float format. I am using the following pointer method to do the conversion

complex_float *comSig = (complex_float *) sigbuf;

where sigbif is an int pointer pointing to the start address of the integer array.

But when i do a printf("%f",comSig[0].re); I am getting some garbage values like -1.#QNAN0.

I have used this technique for data conversion between arrays a number of times on LINUX and it works. Is this a problem related to the mingw compiler not working clearly or is it related to the fact that I am using an incorrect method for converting an int array to struct array.

  • 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-10T10:46:56+00:00Added an answer on June 10, 2026 at 10:46 am

    This is absolutely wrong what you’re doing. Casting a value’s type doesn’t “convert” the values but just tells the compiler to treat it as a different type. As an int and your struct most probably have different sizes, so do the arrays created from them, so you even write/read past the bounds of your integer array. If you really want to convert the integers to complex numbers, you have to code it yourself:

    int number_of_items = 10; // e. g. there are 10 integers
    int *int_arr = // however you obtain the integer array
    complex_float *cpx_arr = malloc(sizeof(*cpx_arr) * number_of_items);
    int i;
    for (i = 0; i < number_of_items; i++)
    {
        cpx_arr[i].re = (float)(int_arr[i]);
        cpx_arr[i].im = 0.0f;
    }
    

    Of course, don’t forget to free(cpx_arr) after use.

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

Sidebar

Related Questions

I'm newly using CODE::BLOCKS+mingw compiler If I don't type return 0 at the end
I have been using the gcc compiler with code::blocks ide, and have noticed there
I'm compiling using Code::Blocks on Windows 7 using the MinGW compiler (which I can
I'm trying to get sqlite3 c-api to compile under windows with code:blocks/gcc mingw compiler
I am using Code::Blocks 10.05, and the GNU GCC Compiler. Basically, I ran into
I'm using the Code::Blocks IDE with the GNU GCC compiler. struct test { char
I have ported some code from Mingw which i wrote using code::blocks, to visual
Using Code::Blocks w/ mingw, and trying to use GLee for some OpenGL on windows.
I'm using Code::Blocks with MinGW to write my C++ applications in Windows XP. Now
I'm making a game in OpenGL on Windows using Code::Blocks (C++) and MinGW. All

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.