전체 글345 [Go] Interface An interface is an abstract concept which enables polymorphism in Go. An interface type is defined as a set of method signatures. A value of interface type can hold any value that implements those methods. An interface increases decoupling so helps you write clean code. Interface Declaration An interface is declared as a type. type INTERFACE_NAME interface{ METHOD_PROTOTYPES } The zero value of .. 2021. 10. 17. [Go] Method A Method is a kind of function. But a method belongs to the receiver. In contrast, function belongs nowhere. Therefore, a method increases the cohesion of code. Method Definition func (RECEIVER) METHOD_NAME() RETURN_TYPE { STATEMENTS } A receiver can be all local types, and local type is defined as type keyword within the package. If a receiver exists, it is a method, and if not, it is a functio.. 2021. 10. 17. [Go] Slice Slice is a scalable collection type, unlike Array. Slice has advantages over Array in terms of memory usage and speed. Slice Declaration var slice []string slice = make([]string, 3) slice[0] = "hello" slice[2] = "hi" fmt.Println(slice[0], slice[1], slice[2]) // hello hi numSlice := make([]int, 3) numSlice[0] = 1 numSlice[1] = 2 numSlice[2] = 3 fmt.Println(numSlice[0], numSlice[1], numSlice[2]) /.. 2021. 10. 16. [Go] Package A package is a bundle of structures, constants, variables, functions, etc. with the same purpose. Using Package If you want to use packages, use import keyword. import "fmt" You can alias to package. import htemplate "html/template" You can import packages even not used. import _ "math" In this case, you don't use the package, but you can get the effects of initializing the package. Go Module Th.. 2021. 10. 16. [Go] Rune and String A string is a set of characters and a string is an immutable. Syntax A rune can be represented by '(single quote) and it means single character. Go supports UTF-8 as a standard character code. package main import "fmt" func main() { fmt.Printf("%c\n", 'G') fmt.Printf("%c\n", '고') fmt.Printf("%c\n", '去') } A string can be represented by "(double-quote) or `(backquote or backtick or grave). A spec.. 2021. 10. 16. [Embedded] Unittest using GoogleTest on CMake In this posting, we will learn how to run a unittest for C. We will use GoogleTest and CMake for this. Prerequisite CMake Please refer to this post. 2021.10.13 - [Embedded] - [C] Build using CMake GoogleTest Clone the googletest into your project. $ git clone https://github.com/google/googletest/ Prepare Project This is the project tree. +-- src +-- main.c +-- calc.h +-- calc.c +-- googletest +-.. 2021. 10. 13. [Embedded] Build using CMake CMake is an open-source, cross-platform build tool. In this posting, we will use CMake to build a C project. Prerequisite CMake You can install the latest CMake on this page. https://cmake.org/download/ I installed it with Homebrew. $ brew install cmake VSCode Extensions If you are using VSCode, you can install these extensions. It will help you a lot. Single File Project Let's create a project... 2021. 10. 13. [Go] Pointer Pointer is a type that has a memory address as a value. Pointer Variable Defining a pointer variable uses a * symbol in front of the type. * symbol is also used to access the value of a pointer variable. And & symbol means the address of a variable. package main import "fmt" func main() { var pNum *int num := 7 // Assign address to pointer pNum = &num // Access to pointer fmt.Println(*pNum) // 7.. 2021. 10. 11. [Go] Structure Structure consists of different types of values. The syntax is following: type STRUCT_NAME struct { FIELD_NAME DATA_TYPE ... } If the name of a structure starts with a capital letter, it is exported to the outside of the package. Structure Declaration var testStruct struct { numField float64 strField string boolField bool } fmt.Println(testStruct) // {0 false}] testStruct.numField = 7 testStruct.. 2021. 10. 11. 이전 1 ··· 15 16 17 18 19 20 21 ··· 39 다음