Comments (6)
The const-ness of UsefulBufC is a core part of the intentional design. We have const char * so there should be const byte strings. I wouldn't want to give that up without a good reason.
I would think having more things const helps the compiler optimize.
From your other PR, I suspect this relates to -Wcast-qual. Is that right? Is there any particular reason this warning is important other than basic general code hygiene? I want to be sure I understand what's going on here.
from qcbor.
Yes, const helps the compiler optimize, as long as the code follows the contract, and in the case of using a UsefulBufC as a result parameter, that definitely breaks things.
For instance in the case of:
const int A = 10;
function(&A);
B=A+1;
The compile is free to optimize "B=A+1" to be "B=11", because A is a constant, and can not change.
If function uses a const busting pragma/cast to change A, which means that the optimized code is incorrect.
This is not about warnings. This is about correctness.
I have been down this rabbit hole 20 years ago with C, and with multiple PhD compiler designers. We tried to make certain code make sense, we ought to be able to mark certain things as const, but often you just can't.
from qcbor.
Sorry, if I'm being dense, but I don't know what is broken yet. How is this broken
QCBOREncode_Finish(QCBOREncodeContext *pCtx, UsefulBufC *pEncodedCBOR);
but this
QCBOREncode_Finish(QCBOREncodeContext *pCtx, const char ** pEncodedCBOR, size_t * pnEncodedCBORsize);
is not broken? Or are they both broken?
I'm not sure what the breakage / incorrectness is.
Is it just that a compiler can't optimize this? I'd be a bit surprised at that. LLVM and GCC are very good these days, better than old compilers. I've looked at their output a little for usage of UsefulBuf and UsefulBufC as a parameter and return value and it seems OK.
from qcbor.
from qcbor.
I can't imagine there's danger of compilers generating incorrect code, code that doesn't execute correctly, because of the const. Thousands of C programmers would have noticed.
So maybe it is not as const as expected. It is still more const that it would be without the const declaration so it is still doing good for the coder.
Can you give a concrete example of some code where something breaks? Then tell me why removing the const would result in less breakage.
from qcbor.
Hi, I guess I will fork QCBOR then.
I don't have time to read the C-specification to you.
from qcbor.
Related Issues (20)
- There doesn't appear to be a way to determine how much space is needed for encoding HOT 4
- OSS-Fuzz integration HOT 2
- Uninitialized data warnings HOT 3
- Preferred Serialization support HOT 1
- Bugs in ieee754.c HOT 12
- Fail to decode an indefinite-length string with a zero-length first chunk. HOT 1
- BstrWrapErrorTest failing on ARM FVP AN521 (release v1.0) HOT 2
- Build error if ARM microlib is used HOT 3
- Enhancement: release QCBOR as MDK Software Pack
- How to decode null terminated string? HOT 2
- UsefulBuf.h gives warnings when used with MSVC HOT 4
- ENCRYPTO should be ENCRYPT0 HOT 1
- Need BKM to use CBOR HOT 2
- Writing an empty null buffer triggers undefined behaviour. HOT 2
- Streaming encoding on the fly HOT 4
- CMake should support installation
- How to use cmake's disable float options? HOT 4
- Warnings when building release tag version 1.2 HOT 9
- Backward compatibility is broken HOT 4
- License file/Github setting HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qcbor.