7

I have the error C4576 in Visual studio 2015 when I tried to compile the file: transcoding.c.

The source code of this file is here: transcoding.c

error C4576: a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax

The error arise at line 127 in this instruction:

enc_ctx->time_base = (AVRational) { 1, enc_ctx->sample_rate };

I used the source of ffmpeg in my project https://www.ffmpeg.org/download.html

I searched around for a solution but I'm not able to correct the error

If someone have found something similar, please provide an idea

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
  • 2
    This is a compound literal. You have to use a C99 or C11 compiler; MSVC is not standard compliant and should not be used for modern C code. And this is C-only. – too honest for this site Oct 21 '15 at 23:30
  • @HocineDJEMAI: No problem, we've fixed the tagging. – MSalters Oct 21 '15 at 23:36
  • 1
    @Olaf it *is* standard compliant, only problem is the standard it complies to is over 25 years old :D –  Oct 21 '15 at 23:36
  • You have an answer, so you cannot, because it is a compound work in the sense of copyright now. Why delete it? However, you may ask the answerers to delete their answers. – too honest for this site Oct 21 '15 at 23:36
  • Is there a chance that the file, despite being a `.c`, is set to compile as C++ in project settings? Also, ignore answers claiming that MSVC compiler does not support C99. MSVC compiler supports virtually all C99 core language features, including compound literals. – AnT stands with Russia Oct 21 '15 at 23:38
  • So it's OK, I know now where is the problem – HDJEMAI Oct 21 '15 at 23:38
  • @FelixPalmen: This again?;-) The only valid standard is C11. All others have been withdrawn. Blame MS they are not able to support these few simple features (I could imagine there is just no one able/willing to maintain the code anymore). – too honest for this site Oct 21 '15 at 23:39
  • .. which why I am asking whether it is somehow being compiled as C++. The feature you are trying to use would be accepted by MSVC compiler in C mode. – AnT stands with Russia Oct 21 '15 at 23:40
  • @Olaf see the instant upvote. You can "withdraw" whatever you like, but you can't invalidate a standard. MSVC still conforms to it. –  Oct 21 '15 at 23:41
  • Yes that's why I'm surprised because [here](https://msdn.microsoft.com/en-us/library/hh409293.aspx?f=255&MSPPError=-2147217396) they say that Visual Studio 2015 fully implements the C99 Standard – HDJEMAI Oct 21 '15 at 23:41
  • Hmm, seems as @AnT is correct. They seem to have condescended to finally [add C99 features](http://www.infoq.com/news/2013/07/vs2013_CPP_compliance). Impressive. Wonder how long it takes they add C11 support. – too honest for this site Oct 21 '15 at 23:44
  • This is probably off-topic, but ... consider it took them >25 years to support C99 -- when would you expect C11? ;) –  Oct 21 '15 at 23:44
  • @Olaf yes, as I already commented, I remember having read something along these lines some time ago ... kind of feels like the hurd hitting stable :D –  Oct 21 '15 at 23:46
  • @FelixPalmen: I would not give too much for an upvote... 1) MSVC is a pretty bad reference. Anyway, if a version of the standard has been withdrawn, it is no longer **the** standard. So done with every previous version once the then new version was released. This is normal, not just for C. – too honest for this site Oct 21 '15 at 23:48
  • @FelixPalmen: >25 Years? Off-by-ten (roughly)?:-) Although I'm always good for critisism to such lazy companies (which well-added to the bad reputation of C), You can only assume lagging once a standard has been released. Anyway, I don't care anymore what MS provides or not - luckily. – too honest for this site Oct 21 '15 at 23:51
  • @Olaf you keep fighting for that, but that's **not** how real life works. Conforming is **still** conforming. Needing 25 years to conform to a newer standard *is* ridiculous, no doubts about that ... but "withdrawing" a document doesn't invalidate a standard. –  Oct 21 '15 at 23:51
  • @Olaf oh sure, that was the first standard. Sorry, replace all "25" by "15" ... STILL ridiculous :) –  Oct 21 '15 at 23:52
  • @Felix Palmen: There's nothing "ridiculous" about Microsoft's C compiler. – AnT stands with Russia Oct 21 '15 at 23:54
  • @FelixPalmen: Not the standard, because that is always the most resent one, but the version. Of course you are free to implement the old version (and apparently some companies treat this as big news ...). Standard is always the latest version, however, the older ones are not approved by the ISO & IEC, so the only ISO/IEC 9899 **standard** is ISO/IEC 9899:2011. – too honest for this site Oct 21 '15 at 23:56
  • @AnT: You are right. It is more of a drama. Or maybe a "dramedy" (drama for its users, comedy for those who can use other compilers). But maybe they just need(ed) all manpower for C#. Anyway, we should clean this up. – too honest for this site Oct 21 '15 at 23:57
  • @Felix Palmen: I hereby override that "LOOOOOOOOL". One more time: There's nothing "ridiculous" about Microsoft's C compiler. And I'm not really offering that for discussion. I'm giving it here to be recorded and thoroughly memorized. – AnT stands with Russia Oct 21 '15 at 23:58
  • @AnT: no need to discuss, just having a good laugh at that statement. –  Oct 21 '15 at 23:59
  • Kids, please calm down! Look,there's a playstation in the corner! ;-) – too honest for this site Oct 21 '15 at 23:59
  • @Olaf: No, it is more of a litmus test to detect wannabees posing as software developers, naively believing that they won't be found out in the first 5 minutes. The well-researched symptom known as "childish microhate" is a dead giveaway :) – AnT stands with Russia Oct 22 '15 at 00:01
  • @AnT there's another giveaway of much greater expressive value: people who think to know shit about others just based on very few statements. In fact, I work exclusively with MS technologies and I'm a huge fan of .NET -- MS just messed up ... (**big time**) with C and everything related (like legacy win32 API, MFC, ...) –  Oct 22 '15 at 00:03
  • @Felix Palmen: Laughing is OK. I'm just trying to point out that sometimes laughter can mean something pertinent to the topic and sometimes it is just means that... well... we are dealing with a reddit-grade LOL-kiddie. – AnT stands with Russia Oct 22 '15 at 00:04
  • @AnT sorry but *not* acknowledging all the crap MS created in context of the C language ... I think that *is* laughable. And no, that's definitely **not** hate towards a company -- I don't care much ;) –  Oct 22 '15 at 00:05
  • @AnT: I would not take someone not being up-to-date with MS' release announcements as a signal for his expertise. MS is well known to announce features they will cancel silently the next day. Just think of what they announced for Vista and have not realised until W10 (e.g. Dtabase File-storage, etc.). Anyway, I'm out of this kindergarten; happily not needing MS stuff and not really caring anymore unless it crosses into my way. – too honest for this site Oct 22 '15 at 00:06
  • @Felix Palmen: Some "very few statements" are a far cry from other "very few statements". Sometimes "very few statements" is more than enough. And I know to tell one from the other. So in this particular case I know very well what I'm talking about. – AnT stands with Russia Oct 22 '15 at 00:07
  • @Olaf: I don't see what "MS release announcements" have to do with this. Frankly, I don't remember ever paying any attention to any of such announcements. – AnT stands with Russia Oct 22 '15 at 00:09
  • @AnT you really think a compiler reaching C99 compliance *this year* isn't pityful? Really, MS should probably just give up on C. The "core" CLR looks kind of promising. –  Oct 22 '15 at 00:14
  • @Felix Palmen: "crap MS created in context of the C language" Er.. What crap? MS's C89/90 compiler is rightfully the most respected C89/90 compiler. They fell behind with their modern C support, but the development community is glad they are catching up. After all, there's no credible replacement for Visual Studio as development environment, regardless of target platform. – AnT stands with Russia Oct 22 '15 at 00:16
  • @AnT this gets close to "fanboy speech". VS does a good job, but a lot more for .NET / CLR code than for C. "The most respected compiler"? Well, **long** time ago. A few years ago, I could get significantly smaller code size with *msvc*, compared to *gcc*. But these times are over. right now, my cross-gcc on linux beats msvc. In the future, the new star will probably be *llvm/clang*. –  Oct 22 '15 at 00:22
  • @AnT and just for completeness .. for quite some while, intel's *icc* was the most respected compiler. And by *crap*, I mean everything around C, especially including the catastrophic win32 API, riddled of crazy all-caps *typedefs* and *hungarian notation*. –  Oct 22 '15 at 00:23
  • 1
    @Felix Palmen: Your cross-gcc might beat msvc as much as it wants (and no, this is not true, as we have seen quite a few times here on SO), but that will only make it a good choice for release builds. I work in a Linux, Linux and only Linux oriented industry, but nevertheless our everyday development (C++ and C in equal proportions) is done in Visual Studio. There's, again, simply no credible competition to VS as an everyday development tool. Not even remotely. – AnT stands with Russia Oct 22 '15 at 00:29
  • @Felix Palmen: Whatever "fanboy speech" might be present in what I said above (if any), it is there for one purpose only: to carefully counterbalance your "fanboy speech". In real life I use absolutely everything without any favoritism. – AnT stands with Russia Oct 22 '15 at 00:32
  • @AnT -- you're the one praising something to be "the best of the best" -- not me. –  Oct 22 '15 at 01:01
  • @Felix Palmen: When it comes to fanboyism, there's no fundamental difference between praising something as "best" or bashing something as "worst". – AnT stands with Russia Oct 22 '15 at 01:15
  • @AnT no "bashing" is needed for Microsoft when it comes to the language [tag:c]. Although I didn't ever say "worst" (a candidate could be "turbo C" or something like that) ... it just IS a mess. –  Oct 22 '15 at 01:20
  • I used turbo C++ 3.0 in the past, it was interesting – HDJEMAI Oct 22 '15 at 01:24
  • 5
    I had the same issue and gogole brought me here. I'm annoyed by the amount of hatred that is spread in comments to this question against Visual Studio. To resolve the error using the C++ compiler simply remove the brackets around `AVRationale` https://reviews.facebook.net/D41889?id=208287 – Bernhard Döbler Jan 03 '16 at 04:04

4 Answers4

9

Despite what some other answers incorrectly claim, VS2015 compiler provides comprehensive support for C99 features, including the compound literal feature you are trying to use in that problematic line.

One possible explanation for the error message is that it the source file, despite being named as .c file, is being compiled as C++ file. The project settings might explicitly request C++ compiler for this file. In C++ this code is invalid.

Check your compilation settings to see if it by any chance includes a /TP ("compile as C++") switch.

AnT stands with Russia
  • 312,472
  • 42
  • 525
  • 765
  • Ok I used the file Source.cpp as proposed by VS2015 and I pasted the content of transcoding.c inside Source.cpp – HDJEMAI Oct 21 '15 at 23:50
  • 1
    @Hocine DJEMAI: Well, then that's the root of the issue. C and C++ are two very different languages, you know. Trying to compile C code as C++ will expectedly lead to problems. Which is exactly what you observed. Your code is written in C. Compile it as C, not as C++. – AnT stands with Russia Oct 21 '15 at 23:51
  • There is no C project in VS that's why I tried that, usually it works every time I handle a C code – HDJEMAI Oct 21 '15 at 23:58
  • @Hocine DJEMAI: Firstly, the fact that "worked every time" for you means nothing. "It worked" for you before by pure random coincidence, since C and C++ do share some common features. But you just discovered that it does not work in general case, since C and C++ also have a lot of incompatible features. Secondly, VS does not need "C projects". You simply create a project and then freely mix C and C++ translation units in that project. Just remember to compile C units as C and C++ units as C++. – AnT stands with Russia Oct 22 '15 at 00:12
6

Remove the parenthesis around the type in the macro definition. That should work.

enc_ctx->time_base = AVRational { 1, enc_ctx->sample_rate };
GANESH B K
  • 381
  • 3
  • 5
5

Old question, but... The solution is pretty simple:

AVRational tb;
tb.num = 1;
tb.den = enc_ctx->sample_rate;

enc_ctx->time_base = tb;

or

enc_ctx->time_base.num = 1;
enc_ctx->time_base.den = enc_ctx->sample_rate;
Dom
  • 532
  • 1
  • 9
  • 23
2

Looks like a question where the C and C++ tags make sense. You're trying to compile C99 code with a C++ compiler. That doesn't work.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • is there an option to compile with C99 with the VS2015 compiler ? – HDJEMAI Oct 21 '15 at 23:10
  • @HocineDJEMAI I don't think so. Your choices are C89, or C++. (Alternatively, edit the code in question to not use C99 syntax. For this particular case, that should be simple) – user253751 Oct 21 '15 at 23:14
  • 1
    Uhm, msvc can compile C (it decides by default based on the input filename), and I recently read something about [tag:c99] support, but can't remember where... –  Oct 21 '15 at 23:15
  • Thanks, i'll search how to compile with C99 – HDJEMAI Oct 21 '15 at 23:18
  • 2
    @HocineDJEMAI really, save yourself the hassle of fighting with *msvc* and try mingw-w64. –  Oct 21 '15 at 23:19
  • This does not recify adding C++ tag, because it is not a problem with the language itself, but a C++ or broken compiler. Edding the VC(++)-tag would be ok, however, as that is the actual problem. – too honest for this site Oct 21 '15 at 23:34