NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

IDE 8.2 (C compiler) reports **non-existent** mismatch between char * and printf's conversion specifier “s” when the char * is typedef'd and accessed through a struct

 
Post new topic   Reply to topic    NetBeans Forums -> C/C++ Users
View previous topic :: View next topic  
Author Message
Bloody Peasant



Joined: 27 May 2017
Posts: 1

PostPosted: Sat May 27, 2017 2:32 am    Post subject: IDE 8.2 (C compiler) reports **non-existent** mismatch between char * and printf's conversion specifier “s” when the char * is typedef'd and accessed through a struct Reply with quote

The following issue resembles a bug purportedly fixed in early 2016: https://netbeans.org/bugzilla/show_bug.cgi?id=258511

Issue:

NetBeans 8.2 IDE (C compiler, see notes at bottom) complains about a mismatched argument type "char" and conversion specifier "s" in the following printf...

Code:
#include <stdio.h>
#include <stdlib.h>
typedef char * STR;     // causes problems in printf below
int main(void) {
    struct MyStruct {
        STR str;
    };
    struct MyStruct ms = {"some text"};
    printf("%s\n", ms.str);
    return (EXIT_SUCCESS);
}


The IDE has no complaint about the same code when the typedef is removed:

Code:

#include <stdio.h>
#include <stdlib.h>
//typedef char * STR;      // runs fine without typedef
int main(void) {
    struct MyStruct {
        char * str; //STR str;
    };
    struct MyStruct ms = {"some text"};
    printf("%s\n", ms.str);
    return (EXIT_SUCCESS);
}


Notes:

(A) System = Win 64, NetBeans IDE 8.2, GCC compiler, no diff whether using Cygwin or MinGW tools, or whether 32 vs 64 bit.

(B) Error is eliminated if I avoid either the struct or the typedef. But error is present whenever using both typedef and struct together as shown.[/list]

(C) This not, apparently, an issue with const, such as was addressed here: stackoverflow.com/questions/20944784/. I rule this out because the IDE alert persists whether typedef is (1) pointer to constant char (typedef char const * STR); (2) constant pointer to char (typedef char * const STR); or (3) constant pointer to constant char (typedef char const * const STR).

(D)
Verbatim error message: Mismatching the argument type "char" and conversion specifier "s".

(E) It appears that ms.str is, indeed, of the expected type char * (e.g., proper sizeof, swapping conversion specifier to "c" for char as indicated by error message results in gibberish as expected if printf'ing pointer to char as a char, etc.)

(F) Changing the name of the typedef identifier (e.g., from STR to STR_TEST) results in same error. So there appears to be no conflict with definitions in standard headers.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> C/C++ Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo