top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

-Wformat cannot use const struct fields as format strings on purpose?

+1 vote
221 views

Here's a small piece of code:

 static struct {
 const char fmt[10];
 } const x = { "%dn" };
 static const char * const fmt = "%dn";
 printf(fmt, 1);
 printf(x.fmt, 1);

The second printf produces a warning:

 test.c:105:10: warning: format string is not a string literal
[-Wformat-nonliteral]
 printf(x.fmt, 1);
 ^~~~~

From my point of view both format strings are identical. Why can't gcc deduce the format string in the second case?

posted Feb 21, 2017 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+1 vote
struct xx
{
 int x;
 struct yy *p;
 struct
 {
 int s;
 };
 struct
 {
 int s;
 };    
};

int main()
{    
 struct xx xyz;
 printf("%d",sizeof(xyz));
 return 0;
}

the above code compile well without any warning. Here my question is
1. How can I distinguish two 's' variable.
2. What is use case.

+4 votes

"Given an array of strings, find the string which is made up of maximum number of other strings contained in the same array. e.g. “rat”, ”cat”, “abc”, “xyz”, “abcxyz”, “ratcatabc”, “xyzcatratabc” Answer: “xyzcatratabc”

0 votes

Can I use gcc as well as java compiler on a single desktop?

+2 votes

Advance apologies if this question has been asked previously, Google searches only turned up results for using -fPIE/-fPIC.

Is it possible to build GCC as a PIE? If so, would it be a matter of including the -FPIC/-FPIE params for CFLAGS and/or LDFLAGS and running configure && make, or are there issues I should be aware of (for example, should I set parameters for cross-building)?

Background: Android 5.0 requires PIE, which means that upgrading will break my existing native build environment...unless I can build a PIE GCC first, then re-build all of my utilities with it.

+2 votes

I need to use microhttpd.a and pthread.a to build a cross-compiled program to be deployed on an arm-linux-gnueabihf device.

Where can I find instructions on how to do this? Or, is this simply a matter of downloading the source code and compiling (on a 64 bit UbuntuPC) to a library with my existing gcc-arm-linux-gnueabihf-4.8 cross-compiler?

While I may be able to find microhttpd.a and pthread.a binaries for an arm-linux-gnueabihf device, they will likely have been built with a different version of gcc-arm-linux-gnueabihf, which, I fear, could open up a can of worms.

...