Rectangle 27 2

-Wstrict-prototypes (C and Objective-C only) Warn if a function is declared or defined without specifying the argument types. (An old-style function definition is permitted without a warning if preceded by a declaration that specifies the argument types.)

hallo.c:1:5: warning: function declaration isnt a prototype [-Wstrict-prototypes]
 int print() {
     ^

However, you'll have to ensure that all non-strict function declarations in your existing code gets properly defined; in particular, functions without parameters should be declared with (void), like this:

int print(void);

That's good if the OP is using GCC, but not complete. If there is no declaration of function print() in scope at all then there is nothing for -Wstrict-prototypes to warn about.

But I'll get warned about int print() {..} (without void) and together with -Wimplicit-function-declaration I have to provide a full prototype. When I want to call print("hello");

How to find use of parameter-type-lists in a C code base? - Stack Over...

c parameters function-declaration
Rectangle 27 78

Usually with warnings like this you can just define a function prototype at the top of your file, for instance:

BOOL FBIsDeviceIPad();

But in C a method with nothing between the braces, i.e. () actually implies there are an arbitrary number of parameters. Instead the definition should become (void) to denote no parameters:

BOOL FBIsDeviceIPad(void);

...

BOOL FBIsDeviceIPad(void) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
  if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   return YES;
  }
#endif
  return NO;
}

I am annoyed very much with this warning, and the "void" keyword in C methods definition explains all.

I too am annoyed: to make my project work without warnings, I had to change the code of something that wasn't mine: glew.c. I know I can build a library from it and link it with the project, but it's just easy to add glew.c. Thanks for the help!

for all who are still annoyed by this issue, update your Facebook SDK. New version is no longer having this issue.

objective c - How to handle the Xcode warning "no previous prototype f...

objective-c xcode warnings
Rectangle 27 1

No, compiler should not optimize the code out in any case unless the global WARNING_ENABLED is declared const.

BTW, if WARN is inline function, you'll still pay the price of message construction (which is very inefficient in your example with lexical_cast and operator+ on strings), even if it's disabled.

Here are some efficient (minimal (close to zero with branch predicting CPU) overhead when runtime disabled) logging macros that support both function and stream style logging.

C++ compiler optimization of passed arguments - Stack Overflow

c++ optimization compiler-construction arguments
Rectangle 27 28

Warning: open_basedir restriction in effect

This warning can appear with various functions that are related to file and directory access. It warns about a configuration issue.

The warning itself does not break anything, but most often a script does not properly work if file-access is prevented.

The fix is normally to change the PHP configuration, the related setting is called open_basedir.

Sometimes the wrong file or directory names are used, the fix is then to use the right ones.

This occurs most often on a shared host, people don't usually lock themselves out of directories :-)

debugging - Reference - What does this error mean in PHP? - Stack Over...

php debugging warnings
Rectangle 27 28

Warning: open_basedir restriction in effect

This warning can appear with various functions that are related to file and directory access. It warns about a configuration issue.

The warning itself does not break anything, but most often a script does not properly work if file-access is prevented.

The fix is normally to change the PHP configuration, the related setting is called open_basedir.

Sometimes the wrong file or directory names are used, the fix is then to use the right ones.

This occurs most often on a shared host, people don't usually lock themselves out of directories :-)

debugging - Reference - What does this error mean in PHP? - Stack Over...

php debugging warnings
Rectangle 27 28

Warning: open_basedir restriction in effect

This warning can appear with various functions that are related to file and directory access. It warns about a configuration issue.

The warning itself does not break anything, but most often a script does not properly work if file-access is prevented.

The fix is normally to change the PHP configuration, the related setting is called open_basedir.

Sometimes the wrong file or directory names are used, the fix is then to use the right ones.

This occurs most often on a shared host, people don't usually lock themselves out of directories :-)

debugging - Reference - What does this error mean in PHP? - Stack Over...

php debugging warnings
Rectangle 27 28

Warning: open_basedir restriction in effect

This warning can appear with various functions that are related to file and directory access. It warns about a configuration issue.

The warning itself does not break anything, but most often a script does not properly work if file-access is prevented.

The fix is normally to change the PHP configuration, the related setting is called open_basedir.

Sometimes the wrong file or directory names are used, the fix is then to use the right ones.

This occurs most often on a shared host, people don't usually lock themselves out of directories :-)

debugging - Reference - What does this error mean in PHP? - Stack Over...

php debugging warnings
Rectangle 27 28

Warning: open_basedir restriction in effect

This warning can appear with various functions that are related to file and directory access. It warns about a configuration issue.

The warning itself does not break anything, but most often a script does not properly work if file-access is prevented.

The fix is normally to change the PHP configuration, the related setting is called open_basedir.

Sometimes the wrong file or directory names are used, the fix is then to use the right ones.

This occurs most often on a shared host, people don't usually lock themselves out of directories :-)

debugging - Reference - What does this error mean in PHP? - Stack Over...

php debugging warnings
Rectangle 27 28

Warning: open_basedir restriction in effect

This warning can appear with various functions that are related to file and directory access. It warns about a configuration issue.

The warning itself does not break anything, but most often a script does not properly work if file-access is prevented.

The fix is normally to change the PHP configuration, the related setting is called open_basedir.

Sometimes the wrong file or directory names are used, the fix is then to use the right ones.

This occurs most often on a shared host, people don't usually lock themselves out of directories :-)

debugging - Reference - What does this error mean in PHP? - Stack Over...

php debugging warnings
Rectangle 27 28

Warning: open_basedir restriction in effect

This warning can appear with various functions that are related to file and directory access. It warns about a configuration issue.

The warning itself does not break anything, but most often a script does not properly work if file-access is prevented.

The fix is normally to change the PHP configuration, the related setting is called open_basedir.

Sometimes the wrong file or directory names are used, the fix is then to use the right ones.

This occurs most often on a shared host, people don't usually lock themselves out of directories :-)

debugging - Reference - What does this error mean in PHP? - Stack Over...

php debugging warnings
Rectangle 27 28

Warning: open_basedir restriction in effect

This warning can appear with various functions that are related to file and directory access. It warns about a configuration issue.

The warning itself does not break anything, but most often a script does not properly work if file-access is prevented.

The fix is normally to change the PHP configuration, the related setting is called open_basedir.

Sometimes the wrong file or directory names are used, the fix is then to use the right ones.

This occurs most often on a shared host, people don't usually lock themselves out of directories :-)

debugging - Reference - What does this error mean in PHP? - Stack Over...

php debugging warnings
Rectangle 27 28

Warning: open_basedir restriction in effect

This warning can appear with various functions that are related to file and directory access. It warns about a configuration issue.

The warning itself does not break anything, but most often a script does not properly work if file-access is prevented.

The fix is normally to change the PHP configuration, the related setting is called open_basedir.

Sometimes the wrong file or directory names are used, the fix is then to use the right ones.

This occurs most often on a shared host, people don't usually lock themselves out of directories :-)

debugging - Reference - What does this error mean in PHP? - Stack Over...

php debugging warnings
Rectangle 27 366

if($content === FALSE) { // handle error here... }
$content = @file_get_contents($site);

Step 2: suppress the warning by putting an @ in front of the file_get_contents: $content = @file_get_contents($site);

Remember to use strict comparison: if ($content === FALSE) .If the file contains "0", then it will trigger a false negative.

Hi, this didn't work for me, adding @ still causes E_WARNING to be caught by some global (not mine) error handler, and my script dies before I have a chance to handle the return value. Any ideas? tnx.

file_get_content
file_get_contents

Why not use error_reporting(~E_WARNING);

How can I handle the warning of file_get_contents() function in PHP? -...

php function exception-handling warnings
Rectangle 27 379

if($content === FALSE) { // handle error here... }
$content = @file_get_contents($site);

Remember to use strict comparison: if ($content === FALSE) .If the file contains "0", then it will trigger a false negative.

Hi, this didn't work for me, adding @ still causes E_WARNING to be caught by some global (not mine) error handler, and my script dies before I have a chance to handle the return value. Any ideas? tnx.

file_get_content
file_get_contents

Why not use error_reporting(~E_WARNING);

How can I handle the warning of file_get_contents() function in PHP? -...

php function exception-handling warnings
Rectangle 27 3

If you consider any form of "confusing" the compiler to be an invalid solution, you're probably going to have to live with the warning. (In my book, if you asking how to get rid of a warning, it's unwise to look a gift horse in the mouth and say something is invalid just because it doesn't look like you'd expect.)

The answers that work at runtime involve masking the operation that's happening with dynamic dispatch so the compiler doesn't complain about the deprecated call. If you don't like that approach, you can turn off "Warn About Deprecated Functions" in your Xcode project or target settings, but that's generally a bad idea. You want to know about deprecated APIs, but in this case you want to use it without warning. There are easy and hard ways to do this, and odds are you'd consider all of them "invalid" in some form, but that doesn't prevent them from being effective, even correct. ;-)

One possible way to avoid the warnings yet still select at runtime is to use objc_msgSend() directly:

objc_msgSend(fileManager, @selector(removeFileAtPath:error:), downloadDir, nil];

Code should say what it means. If it doesn't, then the API, the language, or the programmer is broken. If the compiler is warning when the programmer is confident that his code is correct, then either the compiler needs to learn about that situation and ignore it automatically, or it needs to support a syntax that lets the it ignore that particular warning on that line (like the syntax I posted that doesn't work in the Clang that ships with Xcode). Anything else is a hack.

I applaud your idealism, but sometimes you have to compromise. The code I've posted, and that others have as well, does say what it means. I believe you mean that the compiler should be able to divine your intent based purely on code, without jumping through hoops. That's nice and all, but how do you propose the compiler should know that you'll only call a given method on runtime where it's not deprecated? Without additional semantic information, it really can't. Syntax that can communicate such meaning would be fantastic, but until it exists, calling everything else a hack is unproductive.

Sometimes writing code that isn't crystal clear to the casual observer is unavoidable. This is a perfect time to add a clarifying comment if necessary. Using either performSelector:withObject:withObject: or objc_msgSend() are minimally disruptive approaches that still communicate your meaning and avoid the warning. Java has annotations to suppress warnings, but C does not. Bummer, but life goes on. I'm not defending the current state of things as how it ought to be, just suggesting that if you're going to actually use the language, it's more effective to embrace its quirks than be elitist.

To answer your question: the compiler already has a list of deprecated methods, why not give it a list of alternative methods as well? Then, if it sees a deprecated call, it could look to see if it is inside the else branch of a conditional that tests [<OBJECT> respondsToSelector:@selector(<ALTERNATIVE>))].

I understand your viewpoint, yet I think these answers are about as good as you can expect for now. The deprecated/alternative method approach is an interesting idea, but one that would require fundamental changes to the syntax and semantics of marking code as deprecated. I prefer the safety of compiler checking whenever possible, and avoid casting as id just to avoid warnings. However, spurious warnings tend to distract me more than an occasional hack, particularly when I have unit tests in place to verify that the code work correctly. :-) FWIW, I agree about per-line warning suppression.

objective c - Suppressing "'…' is deprecated" when using respondsToSel...

objective-c cocoa xcode clang
Rectangle 27 3

Sting is a singer, not a C header... Still, the problem is that in C, when you use functions that were not declared, the compiler guesses them to have the types of the arguments you first pass to them and returning an int.

That's the reason why you get all these warnings: several undeclared functions you use don't actually have the deduced signature (although they are not too wrong, and end up working), and the real strtok returns a pointer, not an int (the warning in facts says that you are assigning an int to a pointer without a cast). The crash you are getting most probably comes from the fact that the original pointer is 64 bit, but is truncated to 32 bit when is erroneously considered an int before being assigned to a.

Still, the point to take home is: include headers and don't ever rely on implicit function declaration. It's a dangerous mess that exists only for backward compatibility reasons.

It makes one wonder why the compiler chooses to throw a warning for "implicit function declaration" rather than an error??

@Jay - One that's compiling the code as C90, where it was valid, albeit discouraged. From C99 onward the implicit int rule was abolished.

@StoryTeller, Thanks for the Info. : )

gcc - How is the linking done for string functions in C? - Stack Overf...

c gcc
Rectangle 27 99

set_error_handler(
    create_function(
        '$severity, $message, $file, $line',
        'throw new ErrorException($message, $severity, $severity, $file, $line);'
    )
);

try {
    file_get_contents('www.google.com');
}
catch (Exception $e) {
    echo $e->getMessage();
}

restore_error_handler();

Seems like a lot of code to catch one little error, but if you're using exceptions throughout your app, you would only need to do this once, way at the top (in an included config file, for instance), and it will convert all your errors to Exceptions throughout.

@enobrev, Why do you put the same value for both error number and severity?

No specific reason besides a means of offering something useful in $exception->getCode(), since set_error_handler does not offer an error number variable (unfortunately).

I have a timeout warning that is not catched this way

How can I handle the warning of file_get_contents() function in PHP? -...

php function exception-handling warnings
Rectangle 27 101

set_error_handler(
    create_function(
        '$severity, $message, $file, $line',
        'throw new ErrorException($message, $severity, $severity, $file, $line);'
    )
);

try {
    file_get_contents('www.google.com');
}
catch (Exception $e) {
    echo $e->getMessage();
}

restore_error_handler();

Seems like a lot of code to catch one little error, but if you're using exceptions throughout your app, you would only need to do this once, way at the top (in an included config file, for instance), and it will convert all your errors to Exceptions throughout.

@enobrev, Why do you put the same value for both error number and severity?

No specific reason besides a means of offering something useful in $exception->getCode(), since set_error_handler does not offer an error number variable (unfortunately).

I have a timeout warning that is not catched this way

How can I handle the warning of file_get_contents() function in PHP? -...

php function exception-handling warnings
Rectangle 27 44

if (!$data = file_get_contents("http://www.google.com")) {
      $error = error_get_last();
      echo "HTTP request failed. Error was: " . $error['message'];
} else {
      echo "Everything went better than expected";
}

I found this after experimenting with the try/catch from @enobrev above, but this allows for less lengthy (and IMO, more readable) code. We simply use error_get_last to get the text of the last error, and file_get_contents returns false on failure, so a simple "if" can catch that.

This is the easiest and best solution for this problem! Maybe make it @file_get_contents to supress the error reporting to the browser.

I admit that among all the answers this is the only sensible one -- if we'd augment it to use @file_get_contents to suppress the warning and test the result value using === FALSE.

This will trigger errors for successful requests that don't return a body, or return one that evaluates to false. Should be if (false !== ($data = file_get_contents ()))

How can I handle the warning of file_get_contents() function in PHP? -...

php function exception-handling warnings
Rectangle 27 48

if (!$data = file_get_contents("http://www.google.com")) {
      $error = error_get_last();
      echo "HTTP request failed. Error was: " . $error['message'];
} else {
      echo "Everything went better than expected";
}

I found this after experimenting with the try/catch from @enobrev above, but this allows for less lengthy (and IMO, more readable) code. We simply use error_get_last to get the text of the last error, and file_get_contents returns false on failure, so a simple "if" can catch that.

This is the easiest and best solution for this problem! Maybe make it @file_get_contents to supress the error reporting to the browser.

I admit that among all the answers this is the only sensible one -- if we'd augment it to use @file_get_contents to suppress the warning and test the result value using === FALSE.

This will trigger errors for successful requests that don't return a body, or return one that evaluates to false. Should be if (false !== ($data = file_get_contents ()))

How can I handle the warning of file_get_contents() function in PHP? -...

php function exception-handling warnings