15

I am using Firebase Analytics on my pod file of an iOS project. I get the following errors when I run the app.

A function declaration without a prototype is deprecated in all versions of C

it's shown on the following code (on the Firebase library):

GDTCORNetworkType GDTCORNetworkTypeMessage() {.  <----error here
#if !TARGET_OS_WATCH
  SCNetworkReachabilityFlags reachabilityFlags = [GDTCORReachability currentFlags];
  if ((reachabilityFlags & kSCNetworkReachabilityFlagsReachable) ==
      kSCNetworkReachabilityFlagsReachable) {
    if (GDTCORReachabilityFlagsContainWWAN(reachabilityFlags)) {
      return GDTCORNetworkTypeMobile;
    } else {
      return GDTCORNetworkTypeWIFI;
    }
  }
#endif
  return GDTCORNetworkTypeUNKNOWN;
}

I tried doing a pod update but I'm still unable to fix the problem.

For reference, I have this particular issue besides that I'm on Xcode and not on RN.

Michael Hulet
  • 3,253
  • 1
  • 16
  • 33
MetaSnarf
  • 5,857
  • 3
  • 25
  • 41
  • 5
    Put `void` in the empty parentheses on the error line. – HangarRash Apr 05 '23 at 20:01
  • @HangarRash I have tried unlocking the files and adding them but still no luck – MetaSnarf Apr 05 '23 at 20:08
  • I am not sure why you are getting this error but a prototype of your function is simply `GDTCORNetworkType GDTCORNetworkTypeMessage();`. It is used to split interface and implementation. Try adding this line to the top of your file. But I doubt this would be the only function in the source that has no prototype defined. – Matic Oblak Apr 05 '23 at 20:23
  • 1
    Same as https://stackoverflow.com/questions/75189250/warning-a-function-declaration-without-a-prototype-is-deprecated-in-all-version – Ptit Xav Apr 05 '23 at 21:59
  • Maybe you need update `cocoapods` itself? – Cy-4AH Apr 07 '23 at 09:08

4 Answers4

10

I had the same problem with Firebase Analytics and followed advice in the comments from @HangarRash.

Put void in the empty parentheses on the error line.

There is a 'fix' button which does it for you if you click on the little red x.

It asked me to unlock but that worked OK and could save and build. There were about half a dozen of these to fix, then it builds.

mike nelson
  • 21,218
  • 14
  • 66
  • 75
8

TLDR

Apply the following in your Podfile (post_install)

 post_install do |installer|
    react_native_post_install(installer)
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
    installer.pods_project.targets.each do |target|
      # Make it build with XCode 14
      if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle"
        target.build_configurations.each do |config|
            config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
        end
      end
      # Make it work with GoogleDataTransport
      if target.name.start_with? "GoogleDataTransport"
        target.build_configurations.each do |config|
          config.build_settings['CLANG_WARN_STRICT_PROTOTYPES'] = 'NO' 
        end
      end
    end
  end

Details

First of all, credit to this post in Github.

At the same time, GDT has released the fix too.

Tommy Leong
  • 2,509
  • 6
  • 30
  • 54
1

What it says - functions of the form void func () rather than void func (void) have been flagged as obsolescent by the C standard since the year 1990. So you should (for now) never write functions with an empty parenthesis in C. Unlike C++ where the two forms are equivalent.

In the upcoming C23 standard this will no longer be an issue since the old "K&R style" functions are finally removed from the C language and void func () will get treated as if you typed void func (void).

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • I thought that empty parantheses means a function that takes an unspecified number of arguments? – user129393192 Jun 14 '23 at 01:29
  • @user129393192 It does indirectly since it is a non-prototype format and the compiler can't know the types passed until it finds a function definition. But this was never really a "feature", just a language flaw. – Lundin Jun 14 '23 at 06:21
  • So the common convention `int main()` has always been invalid? I received a compile error with strict compile flags on, and that was a first for me. – user129393192 Jun 15 '23 at 00:29
  • @user129393192 No it (non-prototype format functions) has always been flagged as an obsolescent feature since 1989. Compilers have supported it as required by the standard, but it could have gotten removed at any moment. It finally did with C23, but they chose to synchronize the behavior with C++ so now we can finally type `int main()` without worrying about the feature getting deprecated. Some compilers like clang 16 chose to warn if you compile in strict mode `-std=c17 -pedantic`, but that can be solved by compiling in strict C23 mode `-std=c2x -pedantic`. – Lundin Jun 15 '23 at 05:41
  • @user129393192 It confused me too, see https://stackoverflow.com/questions/76063843/regarding-mainstream-compilers-and-int-main-in-c23 – Lundin Jun 15 '23 at 05:41
  • I see. So you’re saying that the feature of “unknown amount of arguments” got deprecated in 1989 … and now in C23 we finally have it mean “void” … but I didn’t quite catch if compilers in meantime support which version. I think I’m missing a key thing here of when using it in prototype vs the definition itself. – user129393192 Jun 15 '23 at 05:53
  • @user129393192 Between C89 to current C17, there's (C17 6.7.6.3 §14) _"An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied."_ – Lundin Jun 15 '23 at 05:59
  • @user129393192 But in C23 draft N3096 6.7.6.3 §13 _"For a function declarator without a parameter type list: the effect is as if it were declared with a parameter type list consisting of the keyword `void`. A function declarator provides a prototype for the function."_ – Lundin Jun 15 '23 at 05:59
  • So if I'm understanding right, between C89 to C17, a "declarator" with no definition was not a prototype per se, but just some information to let the compiler know that symbol exists ... and now they are saying that the declarator does give a prototype for the function that must be later followed. Seems like if it were in C17 though, it weren't deprecated since C89, unless I'm missing something. – user129393192 Jun 15 '23 at 06:05
  • @user129393192 Yes, a function declarator needed named parameters (or `void`) to have prototype format. This was deprecated in C89 too, I just quoted the current active ISO 9899:2018 ("C17") standard for convenience. In my old copy of C89, then 6.9.5 _"The use of function definitions with separate parameter identifier and declaration lists (not prototype-format parameter type and identifier declarators) is an obsolescent feature._ I think even the esteemed Dennis Ritchie commented about this at some point with regret and in favour of enforcing prototypes. – Lundin Jun 15 '23 at 06:30
  • Understood. So it's just the idea of uniformity that is now being upheld. So back to the original `int main() {}`, it seems like that's been saying that it takes no parameters in C17 (definition-attached), so it is strange to me that the compiler (clang) would yell at me for it. – user129393192 Jun 15 '23 at 19:15
  • @user129393192 Yeah it was a strange call they made. Tbh the latest builds of gcc and clang are so experiemental and out of the loop with bugs and lacking in standard compliance that they can't really be trusted for production purposes. I used to find like at most one bug per year in these compilers, nowadays it's more like one bug per month and that's just my personal findings. And since they are open source, bugs won't get fixed - the maintainers are super busy inventing useless extensions that nobody will use or asked for. It's pretty sad, at least gcc used to be great. – Lundin Jun 16 '23 at 06:50
  • Weird. I'm still not quite sure I fully get it. So the declarator without an item list, even attached to a definition, is not considered a prototype in C17? Specifically referring to what you said: (C17 6.7.6.3 §14) "An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters." Is it because the function [body](https://en.wikipedia.org/wiki/Function_prototype#:~:text=In%20computer%20programming%2C%20a%20function,but%20omits%20the%20function%20body.) is omitted that they did not interpret the dec.+def. to be a prototype? – user129393192 Jun 16 '23 at 07:01
  • It seems to me that if you have the definition, and from the definition, you know it takes no parameters, that would suffice as a prototype, but perhaps they didn't see it that way, because the function body was attached, so it wasn't a "true" prototype? – user129393192 Jun 16 '23 at 07:02
-4

add (void) in every function this error occur on