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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:57:37+00:00 2026-05-18T20:57:37+00:00

Recently I saw following piece code: if ((rgb = (fp16 *)malloc(width*height*sizeof (*rgb)*3)) == NULL)

  • 0

Recently I saw following piece code:

if ((rgb = (fp16 *)malloc(width*height*sizeof (*rgb)*3)) == NULL)

rgb is declared as a pointer of some class type.
In the above code, malloc() is taking arguments which is width*height*sizeof(*rgb)

So it is some kind of self referential initialization(If i may call it by giving this name!)
i.e. belore rgb pointer is allocated by malloc, it is dereferencing it in call to malloc.

In this particular code, i saw that the pointer rgb is not initialized to NULL or anything.

What would be the behaviour of such code.

  • Normal functioning or

  • Crash due to null pointer dereference, or a

  • Garage pointer dereference

thanks,

-AD.

  • 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-18T20:57:38+00:00Added an answer on May 18, 2026 at 8:57 pm

    sizeof does not evaluate its operand, so in this case sizeof(*rgb) will return the size of rgb‘s type, which I assume is fp16 *.

    Completely valid C code.

    If it did evaluate it and the pointer was just some declared pointer with no initialized value, then you would get undefined behavior.

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

Sidebar

Related Questions

I recently saw some XAML code that looked as follows: <Grid.ColumnDefinitions> <ColumnDefinition Width=2* />
I recently saw someone with a T-shirt with some Perl code on the back.
Recently I saw the following code that creates a class in javascript: var Model.Foo
I saw recently following code: #define MY_ASSERT_CONCAT_(a, b) a##b #define MY_ASSERT_CONCAT(a, b) MY_ASSERT_CONCAT_(a, b)
I recently saw something interesting in some c++ code: try { //doStuff } catch
Recently I saw some code like this: <tr> <th> Some label: </th> <td> <input
In some code I saw recently there was a structure defined like this: typedef
I recently saw some Perl code that confused me. I took out all of
I recently came accross some C++ code like the following: if(test_1) if(test_2) { //
Recently i saw this piece of code. Shouldnt this line be a compile error?

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.