microsoft / microsoft/vscode-cpptools
`sizeof` may give incorrect result in editor for structs containing bitfields
Aperta
Nessuno ha ancora preso questa issue.
Language Service
more votes needed
Visual Studio
- Lingua principale
- TypeScript
- Stelle
- 6.2k
- Fork
- 1.7k
- Merge medio
- 14h 46m
- PR unite (30g)
- 61
Descrizione
Bug type: Language Service
Describe the bug
- OS and Version: Ubuntu 20.04
- VS Code Version: 1.61.0
- C/C++ Extension Version: v1.7.0-insiders2
- Other extensions you installed (and if the issue persists after disabling them): N/A
- If using SSH remote, specify OS of remote machine: N/A
- A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc).
Steps to reproduce
Code sample 1
#include <iostream>
struct test1 {
unsigned int a : 4;
unsigned int b : 4;
unsigned char c;
unsigned char d;
};
int main() {
std::cout << sizeof(test1) << std::endl;
}
Expected behavior
sizeof(test1)gives 4 when the program runs. (when memory alignment is set to 4 bytes)- However in the editor it shows 8.
Code sample 2
This time I add #pragma pack(1).
#include <iostream>
#pragma pack(1)
struct test1 {
unsigned int a : 4;
unsigned int b : 4;
unsigned char c;
unsigned char d;
};
int main() {
std::cout << sizeof(test1) << std::endl;
}
Expected behavior
sizeof(test1)gives 3 when the program runs. (when memory alignment is set to 1 byte)- However in the editor it shows 6.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo il problema nell'estensione C/C++ con i due esempi di struct forniti, confrontando il risultato di sizeof dell'editor con l'output del programma. Traccia la gestione di sizeof da parte del servizio linguistico per i bitfield, l'allineamento e #pragma pack. Il lavoro è completato quando l'editor riporta 4 e 3 per i due esempi con le impostazioni di packing indicate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cpp, typescript
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100