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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:15:59+00:00 2026-05-26T03:15:59+00:00

struct AAA { char a_1; int a_2; }; struct BBB { char b_1; int

  • 0
struct AAA
{
    char a_1;
    int a_2;
};

struct BBB
{
    char b_1;
    int b_2;
};


int main(void)
{
    struct AAA a1 = {2, 4};
    struct BBB b1;
    b1 = (struct BBB)a1;
    return 0;
}

as shown above, “b1 = (struct BBB)a1;” made the complie say “error: conversion to non-scalar type requested”.
the struct AAA and the struct BBB have the same type of members, why does this force conversion fail?

thank you

  • 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-26T03:15:59+00:00Added an answer on May 26, 2026 at 3:15 am

    In the C standard (looking at N1256 as it is freely available)

    6.5.4 defines Cast operators.

    6.5.4.2 lists as a restriction on cast operators:

    Unless the type name specifies a void type, the type name shall
    specify qualified or unqualified scalar type and the operand shall
    have scalar type.

    6.2.5.21 describes scalar and aggregate types as:

    Arithmetic types and pointer types are collectively called scalar types. Array and
    structure types are collectively called aggregate types.37)

    A structure type is therefore definitively NOT a scalar type, which means the constraint on the cast operator is not met. Thus, the code fails.

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

Sidebar

Related Questions

struct Dummy { int x; char y; }; int main() { struct Dummy dum;
struct elem { int i; char k; }; elem user; // compile error! struct
struct TimerEvent { event Event; timeval TimeOut; static void HandleTimer(int Fd, short Event, void
struct { char a; int b; } x; Why would one define a struct
typedef struct { nat id; char *data; } element_struct; typedef element_struct * element; void
typedef struct child {int count; char word[100]; inner_list*next;} child; typedef struct parent { char
struct A { int a; virtual void print() {} }; struct B : A
struct match { char men[64]; char women[64]; char menNum[1000]; char woNum[1000]; }; void printOut();
struct bucket { int nStrings; //No. of Strings in a Bucket. char strings[MAXSTRINGS][MAXWORDLENGTH]; //
struct leaf { int data; leaf *l; leaf *r; }; struct leaf *p; void

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.