Why can't I pass in char ** to a function that accepts const char **?

Source: Internet
Author: User
Compile the line below Sv/feature/Cluster
Rc = ns_cluster_insert2db (key_image); error:
Test. c | 47 | error: Invalid conversion from 'Char ** 'to 'const char **'

However, in my test program, I only gave a warning:

  1. # Include <stdio. h>
  2. Int main (){
  3. Char ** _ P;
  4. Fun (_ P );
  5. }
  6. Void fun (const char ** p ){
  7. Printf ("test/N ");
  8. }
  9. ~
  10. ~

I checked the c faq. I have not understood the following section:

11.10 why can't I pass in char ** to a function that accepts const char **?
You can pass the T pointer to the place where the const-T pointer is accepted (applicable to any type of T ). However
Yes. This rule allows slight unmatched types of pointers with modifiers (obvious exceptions) but cannot be recursive.
Application, but only for the top layer.
If you must assign a value or pass a pointer that does not match the modifier in addition to the top layer, you must specify
Use type conversion (in this example, use (const char **).
There are also deep-seated problems that cannot be fixed by conversion.
References: [ISO, sec. 6.1.2.6, sec. 6.3.16.1, sec. 6.5.3]; [H & S, sec. 7.9.1 pp.
221-2]

Find the cause of the problem. Test. C is compiled using gcc, but the call of the ns_cluster_insert2db (key_image) function is the shared library libnscluster compiled by G ++. so is provided, so the ns_cluster_insert2db function processes input parameters in C ++ mode, and the type conversion rules of C ++ are more strict, so compile test. the invalid Conversion error occurs in C.

The following is part of makefile:
Libnscluster. So: $ (SRC)
G ++-shared-o $ ^ $ (libpath) $ (LIB) $ (include)
Test: Test. c libnscluster. So
Gcc-g-o $ @ $ <$ (include) $ (libpath) $ (LIB)-llpool-lnsrcluster

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.