Tag Archives: C language

[Solved] igb Compile Error: igb_main.c:10044:7: error: implicit declaration of function ‘isdigit’

Recently, the IGB compiler driver found this problem:

zacha@Superman:~/igb/igb-5.7.2/src$ make
#@+ echo "*** The target kernel has CONFIG_MODULE_SIG_ALL enabled, but" ; echo "*** the signing key cannot be found. Module signing has been" ; echo "*** disabled for this build." ; make  ccflags-y="" -C "/lib/modules/4.15.0-142-generic/build" CONFIG_IGB=m CONFIG_MODULE_SIG=n CONFIG_MODULE_SIG_ALL= M="/home/zacha/igb/igb-5.7.2/src"   modules  
make -C /home/zacha/yulong810/kernel M=/home/zacha/igb/igb-5.7.2/src CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm
make[1]: Entering directory '/home/zacha/yulong810/kernel'
  CC [M]  /home/zacha/igb/igb-5.7.2/src/igb_main.o
/home/zacha/igb/igb-5.7.2/src/igb_main.c: In function ‘igb_get_os_driver_version’:
/home/zacha/igb/igb-5.7.2/src/igb_main.c:10044:7: error: implicit declaration of function ‘isdigit’ [-Werror=implicit-function-declaration]
   if(!isdigit(*c) && *c != '.')
       ^~~~~~~
cc1: some warnings being treated as errors
scripts/Makefile.build:303: recipe for target '/home/zacha/igb/igb-5.7.2/src/igb_main.o' failed
make[2]: *** [/home/zacha/igb/igb-5.7.2/src/igb_main.o] Error 1
Makefile:1519: recipe for target '_module_/home/zacha/igb/igb-5.7.2/src' failed
make[1]: *** [_module_/home/zacha/igb/igb-5.7.2/src] Error 2
make[1]: Leaving directory '/home/zacha/yulong810/kernel'
Makefile:88: recipe for target 'default' failed
make: *** [default] Error 2

There are also solutions online:
https://github.com/geerlingguy/raspberry-pi-pcie-devices/issues/3

Solution:

Add #include <linux/ctype.h> inigb)main.c
then compile and generate IGB.ko

zacha@Superman:~/igb/igb-5.7.2/src$ make
#@+ echo "*** The target kernel has CONFIG_MODULE_SIG_ALL enabled, but" ; echo "*** the signing key cannot be found. Module signing has been" ; echo "*** disabled for this build." ; make  ccflags-y="" -C "/lib/modules/4.15.0-142-generic/build" CONFIG_IGB=m CONFIG_MODULE_SIG=n CONFIG_MODULE_SIG_ALL= M="/home/zacha/igb/igb-5.7.2/src"   modules  
make -C /home/zacha/yulong810/kernel M=/home/zacha/igb/igb-5.7.2/src CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm
make[1]: Entering directory '/home/zacha/yulong810/kernel'
  CC [M]  /home/zacha/igb/igb-5.7.2/src/igb_main.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/e1000_api.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/igb_ethtool.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/igb_hwmon.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/e1000_mbx.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/e1000_mac.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/e1000_manage.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/e1000_nvm.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/igb_param.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/e1000_phy.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/igb_procfs.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/igb_vmdq.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/e1000_82575.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/e1000_i210.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/igb_debugfs.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/igb_ptp.o
  CC [M]  /home/zacha/igb/igb-5.7.2/src/kcompat.o
  LD [M]  /home/zacha/igb/igb-5.7.2/src/igb.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/zacha/igb/igb-5.7.2/src/igb.mod.o
  LD [M]  /home/zacha/igb/igb-5.7.2/src/igb.ko
make[1]: Leaving directory '/home/zacha/yulong810/kernel'

Vmware Virtual Machine ubuntu Compile Error: fatal error: Killed signal terminated program cc1plus

VMware virtual machine
Ubuntu compiles opencv with an error of 92%.
fatal error: killed signal terminated program cc1plus.

Cause: the virtual machine is out of allocated memory.

Close the client, edit the client settings, and expand the memory to 4G.

After confirmation, restart the virtual machine and execute the compile command again. Generally, the system will compile and will not restart.

Function declare Error: Error C231: ‘delay300us’: redefinition

First of all, we know that we can’t avoid declaring sub functions when writing programs.

There was a problem during the test today:

After thinking about it, I declared the function in the previous writing, but the error “redefinition” was still reported. Later, I tried it

You need to prefix the function name with “void”.

error: stray ‘\343’ in program [How to Solve]

Problem phenomenon:

Cause of problem:

This error is basically generated by copying the code from the web page and compiling it. Because the copied code contains Chinese spaces and characters, it can’t be distinguished by the naked eye.

Solution:

1. When the amount of code is small, it is best to re type it at the error location, then save it and recompile it.

Error prompts the location information of the error. Find the corresponding place to change.

2. It can also be used when there are many codes, or the replacement function of GEDIT can be used to replace with standard spaces, which is more labor-saving.

Find characters in error:

Under Linux, you can:

cat xxx.c -A

Chinese will be displayed as characters with red lines.

[Solved] Linux R Pack Error: cram/cram_io.c:61:10: fatal error: lzma.h: No such file or directory

Error message

Operating system: Ubuntu 20.04 64 bit

An error occurred while installing rhtslib package. Error message:

> BiocManager::install("Rhtslib")
cram/cram_io.c:61:10: fatal error: lzma.h: No such file or directory
   61 | #include <lzma.h>
      |          ^~~~~~~~
compilation terminated.
make[1]: *** [Makefile.Rhtslib:128: cram/cram_io.o] Error 1
make[1]: Leaving directory '/tmp/Rtmp428cj4/R.INSTALL14a4e8febbab/Rhtslib/src/htslib-1.7'
make: *** [Makevars.common:24: htslib] Error 2
ERROR: compilation failed for package ‘Rhtslib’
* removing ‘/usr/local/lib/R/site-library/Rhtslib’

The downloaded source packages are in
	‘/tmp/RtmpcHBCud/downloaded_packages’

Solution:

Generally, the compilation fails due to the lack of packages in the system. Solve such problems by installing libbz2 dev, zlib1g Dev and liblzma dev:

sudo apt-get install libbz2-dev
sudo apt-get install zlib1g-dev
sudo apt-get install liblzma-dev

[Solved] Keil C Error: error C141: syntax error near ‘=‘, expected ‘__asm‘

1. This code is a clock code designed for the timer T0 programming of 89C52 single-chip microcomputer.

#include<reg52.h>
unsigned char code ledcode[]={0x3f,0x5b,0x4f,0x66,0x7d,7,0x7f,0x6f};	//Segment selection code for common cathode 0-9
unsigned char data hou,min,sec,num,disbuf[]={0,0,10,0,0,0,10,0,0}; //hour,minute,sec,num is the number of T0 interrupts,disbuf is the number of displayed digits
#define codport P0; //Display segment output port
#define sitport P2; //Display bit code output port

void display() //display function
{
	unsigned int j; //for loop
	unsigned char i,scan; //scan is the bit code of the output control display bit, also called scan code
	scan=0x01;
	for(i=0;i<6;i++)
	{
		codport=0; //Display new content before clearing the screen, otherwise it will be displayed incorrectly in Proteus
		codport=ledcode[disbuf[i]]; //the number to be displayed send break code port
		sitport=~scan; //Bit code port low corresponding bit valid, lit
		scan=(scan<<1);
		for(j=0;j<500;j++);
	}
}

2、In the following program, the compilation shows an error
clock.c(14): warning C275: expression with possibly no effect
clock.c(14): error C141: syntax error near ‘=’, expected ‘__asm’
clock.c(15): error C141: syntax error near ‘=’, expected ‘__asm’
clock.c(16): error C141: syntax error near ‘=’, expected ‘__asm’
clock.c – 3 Error(s), 1 Warning(s).
Locating the error found is

codport=0; //clear the screen before displaying new content, otherwise it will be displayed incorrectly in Proteus
codport=ledcode[disbuf[i]]; //the number to be displayed is sent to the code breaking port
sitport=~scan; //Bit code port low corresponding bit valid, lit

3. Since bit operations are required for codport and sitport, the modified macro is defined as

#include<reg52.h>
unsigned char code ledcode[]={0x3f,0x5b,0x4f,0x66,0x7d,7,0x7f,0x6f};	//Segment selection code for common cathode 0-9
unsigned char data hou,min,sec,num,disbuf[]={0,0,10,0,0,0,10,0,0}; //hour,minute,sec,num is the number of T0 interrupts,disbuf is the number of displayed digits
sibt codport=P0; //display segment code output port
sbit sitport=P2; //display bit code output port

4. Compiled successfully after modification

Error creating bean with name ‘captchaController‘: Unsatisfied dependency expressed through field ‘c

Error creating bean with name 'captchaController': Unsatisfied dependency expressed through field 'configService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysConfigServiceImpl': Invocation of init method failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379
Check start Redis or not

Error in `./a.out‘: free(): invalid next size (fast): 0x0000000001da8010

Error in `./a.out’: free(): invalid next size (fast): 0x0000000001da8010

*** Error in `./a.out': free(): invalid next size (fast): 0x0000000001da8010 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777f5)[0x7f216399b7f5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8038a)[0x7f21639a438a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f21639a858c]
./a.out[0x400896]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f2163944840]
./a.out[0x400609]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:01 1155                               /home/csgec/C++/a.out
00600000-00601000 r--p 00000000 08:01 1155                               /home/csgec/C++/a.out
00601000-00602000 rw-p 00001000 08:01 1155                               /home/csgec/C++/a.out
01da8000-01dc9000 rw-p 00000000 00:00 0                                  [heap]
7f215c000000-7f215c021000 rw-p 00000000 00:00 0 
7f215c021000-7f2160000000 ---p 00000000 00:00 0 
7f216370e000-7f2163724000 r-xp 00000000 08:01 923094                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f2163724000-7f2163923000 ---p 00016000 08:01 923094                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f2163923000-7f2163924000 rw-p 00015000 08:01 923094                     /lib/x86_64-linux-gnu/libgcc_s.so.1
7f2163924000-7f2163ae4000 r-xp 00000000 08:01 953576                     /lib/x86_64-linux-gnu/libc-2.23.so
7f2163ae4000-7f2163ce4000 ---p 001c0000 08:01 953576                     /lib/x86_64-linux-gnu/libc-2.23.so
7f2163ce4000-7f2163ce8000 r--p 001c0000 08:01 953576                     /lib/x86_64-linux-gnu/libc-2.23.so
7f2163ce8000-7f2163cea000 rw-p 001c4000 08:01 953576                     /lib/x86_64-linux-gnu/libc-2.23.so
7f2163cea000-7f2163cee000 rw-p 00000000 00:00 0 
7f2163cee000-7f2163d14000 r-xp 00000000 08:01 953568                     /lib/x86_64-linux-gnu/ld-2.23.so
7f2163ef7000-7f2163efa000 rw-p 00000000 00:00 0 
7f2163f12000-7f2163f13000 rw-p 00000000 00:00 0 
7f2163f13000-7f2163f14000 r--p 00025000 08:01 953568                     /lib/x86_64-linux-gnu/ld-2.23.so
7f2163f14000-7f2163f15000 rw-p 00026000 08:01 953568                     /lib/x86_64-linux-gnu/ld-2.23.so
7f2163f15000-7f2163f16000 rw-p 00000000 00:00 0 
7ffcd77e9000-7ffcd780a000 rw-p 00000000 00:00 0                          [stack]
7ffcd798b000-7ffcd798e000 r--p 00000000 00:00 0                          [vvar]
7ffcd798e000-7ffcd7990000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
fish: Job 2, “./a.out” terminated by signal SIGABRT (Abort)

resolvent:

unsigned int *a = (unsigned int *)malloc(sizeof(unsigned int) * 2 * n);

Malloc dynamically allocates memory. N must have confirmed the value
① you can add int n = 5 before applying for space

int n = 5;
    unsigned int *a = (unsigned int *)malloc(sizeof(unsigned int) * 2 * n);

⑤ You can also allocate space after user input, so that the value of n is known
unknown dynamic space cannot be allocated before user input.

 scanf("%d %d",&n,&m);
   // getchar();
    unsigned int *a = (unsigned int *)malloc(sizeof(unsigned int) * 2 * n);

After correction, the error report can disappear.

[Solved] iperf Analyze Error: unable to create a new stream: Invalid argument

The root cause of the error reported in the title is that the iperf command code customized by the company is relatively old, so the open source code still needs to be updated in time!

Device: Android p

Problem: when the iperf server is opened on the PC and the iperf client is opened on the Android device, the throughput cannot be tested normally, as shown in the following figure:

The Android device reports an error “unable to create a new stream: invalid argument”. The PC can see that there is a connection at the beginning, and then the connection is closed due to the client.

Solution:

First look at the error report, “Unable to create a new stream” corresponds to “case IECREATESTREAM”. It can be determined that this error occurs in a function of iperf_api, and it is found in the iperf_new_stream() function. It is simple here. Exclude the first few A malloc, the first function mkstemp(), this function is interesting, the actual problem is also here, first introduce this function.

The mkstep function creates a file with a unique file name in the system and opens it. Only the current user can access the temporary file and perform read and write operations. The mkstamp function has only one parameter template, which is a non empty string ending in “XXXXXX”. The mkstemp function will replace “XXXXXX” with a randomly generated string to ensure the uniqueness of the file name.

You can see the common error codes eexist and einval through the man Manual:

1>   EEXIST:   Unable to create a unique temporary file, the content of parameter template is undefined;

2>   Einval: for mkstamp(), the last six characters of template are not XXXXXX;

It is worth mentioning that in glibc 2.0.6 and earlier glibc libraries, the access permission of this file is 0666, that is, all users in UNIX system can access it, which will have a big problem. Therefore, the access permission of this file in glibc libraries after glibc 2.0.7 is adjusted to 0600.

The temporary file created by the mkstemp function cannot be deleted automatically, so after executing the mkstemp function, you need to call the unlink function. The unlink function deletes the directory entry of the file, but the temporary file can also be accessed through the file descriptor until the last open process closes the file, or the temporary file is automatically and completely deleted after the program exits.

The original code snippet of the error is as follows

struct iperf_stream *iperf_new_stream(struct iperf_test *test, int s)
{
    int i;
    struct iperf_stream *sp;
    //The problem is here, the template parameter format is incorrect
    char template[] = "/data/data/iperf3.0.11";
    ......
    /* Create and randomize the buffer */
    sp->buffer_fd = mkstemp(template);
    if (sp->buffer_fd == -1) {
        i_errno = IECREATESTREAM;
        free(sp->result);
        free(sp);
        return NULL;
    }
    if (unlink(template) < 0) {
        i_errno = IECREATESTREAM;
        free(sp->result);
        free(sp);
        return NULL;
    }
    if (ftruncate(sp->buffer_fd, test->settings->blksize) < 0) {
        i_errno = IECREATESTREAM;
        free(sp->result);
        free(sp);
        return NULL;
    }
    ......

It’s clear from here that the problem with the template parameter causes an error in mkstamp() and returns einval. The corresponding Android device executes the iperf command and reports an error of ‘invalid argument’. I was going to make a simple change. After thinking about iperf, everyone is using it. There should be no big problem. I went to GitHub community and found that predecessors have paved the way. I changed it with reference to the submission in the community.

diff --git a/system/core/swiperf/iperf.h b/system/core/swiperf/iperf.h
index f4d394b..2bc0b73 100644
--- a/system/core/swiperf/iperf.h
+++ b/system/core/swiperf/iperf.h
@@ -178,6 +178,7 @@ struct iperf_test
     struct protocol *protocol;
     signed char state;
     char     *server_hostname;                  /* -c option */
     //The latest open source code iperf_test structure itself has tmp_template
+    char     *tmp_template;
     char     *bind_address;                     /* -B option */
     int       server_port;
     int       omit;                             /* duration of omit period (-O flag) */
@@ -252,6 +253,9 @@ struct iperf_test
     char *server_output_text;
     cJSON *json_server_output;

+    /* Store User Defined Path and use it for creating temporary streams */
+    char *user_stream_path;
+
     /* Server output (use on server side only) */
     TAILQ_HEAD(iperf_textlisthead, iperf_textline) server_output_list;

diff --git a/system/core/swiperf/iperf_api.c b/system/core/swiperf/iperf_api.c
index 13269d5..27a92ac 100644
--- a/system/core/swiperf/iperf_api.c
+++ b/system/core/swiperf/iperf_api.c
@@ -27,6 +27,9 @@
 #define _GNU_SOURCE
 #define __USE_GNU

+/* Suppress Warning generated by GCC __attribute__ for write */
+#pragma GCC diagnostic ignored "-Wunused-result"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -235,8 +238,21 @@ iperf_get_test_one_off(struct iperf_test *ipt)
     return ipt->one_off;
 }

-/************** Setter routines for some fields inside iperf_test *************/
+/* Getter routine for user-defined stream-path */
+char *
+iperf_get_stream_path(struct iperf_test *ipt)
+{
+    return ipt->user_stream_path;
+}

+/* Setter routine for user-defined stream-path */
+void
+iperf_set_stream_path(struct iperf_test *ipt, char *_stram_path)
+{
+    ipt->user_stream_path = strdup(_stram_path);
+}
+
+/************** Setter routines for some fields inside iperf_test *************/
 void
 iperf_set_verbose(struct iperf_test *ipt, int verbose)
 {
@@ -596,6 +612,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
        {"get-server-output", no_argument, NULL, OPT_GET_SERVER_OUTPUT},
         {"debug", no_argument, NULL, 'd'},
         {"help", no_argument, NULL, 'h'},
         //Add the analysis of the corresponding parameters
+        {"stream-path", required_argument, NULL, OPT_STREAM_PATH},
         {NULL, 0, NULL, 0}
     };
     int flag;
@@ -608,6 +625,15 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
     server_flag = client_flag = rate_flag = duration_flag = 0;
     while ((flag = getopt_long(argc, argv, "p:f:i:D1VJvsc:ub:t:n:k:l:P:Rw:B:M:N46S:L:ZO:F:A:T:C:dh", longopts, NULL)) != -1) {
         switch (flag) {
+            /*
+             * Set Stream Path to user-defined path
+             * Reason: To work on Android as /tmp is not available on Android
+             * also access to a static /data/local/tmp/ is also restricted for Applications
+             * Only native application path is accessable with complete permissions
+             */
+            case OPT_STREAM_PATH:
+                iperf_set_stream_path(test, optarg);
+                break;
             case 'p':
                 test->server_port = atoi(optarg);
                 break;
@@ -2367,7 +2393,27 @@ iperf_new_stream(struct iperf_test *test, int s)
 {
     int i;
     struct iperf_stream *sp;
-    char template[] = "/data/data/iperf3.0.11";
+    char template[1024];
+    if (test->tmp_template) {
+        snprintf(template, sizeof(template)/sizeof(char), "%s", test->tmp_template);
+    } else {
+        //find the system temporary dir *unix, windows, cygwin support
+        char* tempdir = getenv("TMPDIR");
+        if (tempdir == 0) {
+            tempdir = getenv("TEMP");
+        }
+        if (tempdir == 0) {
+            tempdir = getenv("TMP");
+        }
+        /* Use User Specific Path if available */
+        if (test->user_stream_path != NULL) { //There is a pass to go here
+            tempdir = iperf_get_stream_path(test);
+        }
+        if (tempdir == 0) { // Android devices without parameters, create temporary files under /tmp by default
+            tempdir = "/tmp";
+        }
+        snprintf(template, sizeof(template)/sizeof(char), "%s/iperf3.XXXXXX", tempdir);
+    }

     h_errno = 0;

diff --git a/system/core/swiperf/iperf_api.h b/system/core/swiperf/iperf_api.h
index c019a31..e19492b 100644
--- a/system/core/swiperf/iperf_api.h
+++ b/system/core/swiperf/iperf_api.h
@@ -44,6 +44,8 @@ struct iperf_stream;
 #define OPT_SCTP 1
 #define OPT_LOGFILE 2
 #define OPT_GET_SERVER_OUTPUT 3
+/* Stream Path Edit for Android Compatibility */
+#define OPT_STREAM_PATH 4

 /* states */
 #define TEST_START 1
@@ -87,6 +89,10 @@ int  iperf_get_test_zerocopy( struct iperf_test* ipt );
 int    iperf_get_test_get_server_output( struct iperf_test* ipt );
 char*  iperf_get_test_bind_address ( struct iperf_test* ipt );
 int    iperf_get_test_one_off( struct iperf_test* ipt );
+/* Getter routine for user-defined stream-path */
+char* iperf_get_stream_path( struct iperf_test *ipt );
+/* Setter routine for user-defined stream-path */
+void iperf_set_stream_path( struct iperf_test *ipt, char *_stram_path );

 /* Setter routines for some fields inside iperf_test. */
 void   iperf_set_verbose( struct iperf_test* ipt, int verbose );
diff --git a/system/core/swiperf/iperf_locale.c b/system/core/swiperf/iperf_locale.c
index 30e6290..9fe7ba6 100644
--- a/system/core/swiperf/iperf_locale.c
+++ b/system/core/swiperf/iperf_locale.c
@@ -141,6 +141,7 @@ const char usage_longstr[] = "Usage: iperf [-s|-c host] [options]\n"
                            "  -O, --omit N              omit the first n seconds\n"
                            "  -T, --title str           prefix every output line with this string\n"
                            "  --get-server-output       get results from server\n"
                            //New --stream-path passing parameter, support custom write path
+                           "  --stream-path             use user-defied path to create temporary stream\n"

 #ifdef NOT_YET_SUPPORTED /* still working on these */
 #endif

[Solved] Error ‘false‘ undeclared (first use in this function)

Error: ‘false’ undeclared (first use in this function)

When you knock the code with DEVC + +, you will report an error to the following program

bool ok(int t){
	//Determine whether the tth person's job is assigned or not; if it is not assigned then a[j] = 0, otherwise a[j] = 1. 
	int i;
	for(i=0;i<t;i++)
		if(a[i]==a[t])
			return false;
		return true;
}

analysis:

There are no these keywords in real C. There is no keyword bool in C and early C + +. Bool can be used, but bool is not a built-in type. It is defined through typedef or macros. It is usually defined as int type. Later, the built-in type bool appeared in C + +, and the values can only be true (1) and false (0).

Solution 1:

Change the file type to CPP

Solution 2:

Macro definition of bool:

typedef enum __bool { false = 0, true = 1, } bool; 

2021-11-08 error: could not convert ‘{0}‘ from ‘<brace-enclosed initializer list>‘ to

could not convert ‘{0}’ from ‘《brace-enclosed initializer list>’ to

C + + program, using the usual initialization list today, actually reported an error

struct sales {
    char bookNo;
    unsigned units_sold = 0;
    double revenue = 0.0;
};

int main() {
    sales a = {0};
    // print(cout, a);
}

error message

cpp_primer.cc:62:17: error: could not convert '{0}' from '<brace-enclosed initializer list>' to 'sales'
   62 |     sales a = {0};
      |                 ^
      |                 |
      |                 <brace-enclosed initializer list>

The problem is that the initial value is defined in the structure. At this time, the initialization list cannot be used

Change the structure to

struct sales {
    char bookNo;
    unsigned units_sold;
    double revenue;
};

That’s it

Summary

There are two initialization methods:

    when defining a structure, the initial value is given to initialize the list assignment

    The above two methods are mutually exclusive, and only one can be selected

    reference material https://qa.1r1g.com/sf/ask/2644377641/