VSC “Format Document” messes up #include order - c++

My problem is pretty much what the title says:
When I use STRG-ALT-F to format my C++ files VSC also messes with the order of #includes.
And of cause this leads to errors that were not there before… :-(
For example this
#include "soc/soc.h"
#include "soc/gpio_sig_map.h"
#include "soc/i2s_reg.h"
#include "soc/i2s_struct.h"
#include "soc/io_mux_reg.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "XClk.h"
#include "DMABuffer.h"
becomes this
#include "DMABuffer.h"
#include "XClk.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "soc/gpio_sig_map.h"
#include "soc/i2s_reg.h"
#include "soc/i2s_struct.h"
#include "soc/io_mux_reg.h"
#include "soc/soc.h"
… and subsequently fails compile.
Is there a way to forbid the formatter reordering and stick to formatting stuff?
Using PlatformIO in VSC on OSX.

Related

Why does including several libraries throw Runtime Error(SIGILL)?

I was getting SIGILL Runtime Error on one of my codes.
But then i noticed that just changing the libraries used made it run normally.
Previous code(throws Runtime Error on C++14):
#pragma GCC target("avx2")
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
Modified version(Gave AC on C++14):
#include<bits/stdc++.h>
What might be the reason for this?

Add references in system so that not to include again?

I want to add #include "List.h"
in reference for that purpose i have to add sys machine vm bsm and other references files that are 100 in number my code not accepting this
<sys/kernel.h>
so i have to manually download and add like that
#include "sys/param.h"
#include <sys/kernel.h>
#include "sys/queue.h"
#include "sys/cpuset.h"
#include "sys/lock.h"
#include "sys/mutex.h"
#include "sys/proc.h"
#include "sys/vnode.h"
#include "sys/conf.h"
#include "sys/socket.h"
#include "sys/mbuf.h"
#include "sys/bpf.h"
#include "sys/if.h"
#include "sys/if_var.h"
#include "sys/if_types.h"
#include "sys/if_media.h"
#include <netinet/in.h>
#include <netinet/in_pcb.
#include <netinet6/in6_va
#include <netinet6/nd6.h>
#include "vm/vm.h"
#include <vm/vm_object.h>`
this create further problem like i have to add more files the basic file i need is List.h header file so can anybody tell me solution from "sys/kernal.h" to <sys/kernal.h> and where is List.h

Why is SRWLock undefined?

I'm trying to use SRWLock with C++ project Visual Studio 2012 (Windows 7) targeting 32-bit Windows only and SRWLock is better then CriticalSections in my case.
As i've searched, i should include WinBase.h and use std namespace. But SRWLock is still undefined. Couldn't find anything useful on Google. What i'm missing? I appreciate any clues.
Code:
#include <cstdlib>
#include <winsock2.h>
#include <Ws2tcpip.h>
#include <windows.h>
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <conio.h>
#include <WinBase.h>
using namespace std;
SRWLock gLock; // here is the problem
Where was a mistype: Should be SRWLOCK instead of SRWLock.
And you need
#include <windows.h>

Compile errors when attempting to link <boost\property_tree\json_parser.hpp>

I have the following "includes" file in my project.
#pragma once
//glm
#include <glm\glm.hpp>
#include <glm\ext.hpp>
#include <glm\gtc\matrix_transform.hpp>
//glew
#include "GL\glew.h"
//glfw
#define GLFW_DLL
#include "GLFW\glfw3.h"
//libpng
#include <png.h>
//std
#include <stdio.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <memory>
#include <iostream>
#include <fstream>
#include <assert.h>
//boost
#include <boost\filesystem.hpp>
#include <boost\property_tree\json_parser.hpp> /* problem */
//mandala
#include "types.h"
#include "type_traits.h"
#include "hash.h"
#include "macros.h"
When I include <boost\property_tree\json_parser.hpp>, I get many errors indicating that I'm redefining APIENTRY such as this one:
1>c:\program files (x86)\windows kits\8.0\include\shared\minwindef.h(130): warning C4005: 'APIENTRY' : macro redefinition
I'm perplexed as to why this is happening. I've tried to suppress the minwindef.h file from being processed by putting #define _MINWINDEF_ before the include statement but to no avail. Has anyone else encountered this or have any idea how I can properly include this boost library?
NOTE
Since youd did neither update your question to reflect the changes to the includes you made, nor provide the whole warning message, I can only guess:
You still have glfw.h included before the boost lib that includes the WinAPI header. Because when I just google for "APIENTRY redefinition", I get this SO question as first result, including the answer: Put the WinAPI header (or the boost header includign them) before the glfw.h include.
You may want to include also ptree.
#include <boost/property_tree/ptree.hpp>

Weird VC++ Intellisense Behavior

Intellisense is broken with this code, everything is undefined to Intellisense from tree header:
#include "tree.h"
#include <iostream>
#include <ctime>
#include <string>
#include <list>
But when I move my own bst implementation header file down a bit, Intellisense starts working again.
#include <iostream>
#include <ctime>
#include <string>
#include <list>
#include "tree.h"
Why is this?